| False | None | True | and | as |
| assert | break | class | continue | def |
| del | elif | else | except | finally |
| for | from | global | if | import |
| in | is | lambda | nonlocal | not |
| or | pass | raise | return | try |
| while | with | yield |
#导入keyword 模块 import keyword #显示所有关键字 keyword.kwlist从上面代码可以看出,程序只要先导入 keyword 模块,然后调用 keyword.kwlist 即可查看 Python 包含的所有关键字。运行上面程序,可以看到如下输出结果:
['False','None','True','and','as','assert','break','class','continue','def','del','elif','else','except','finally','for','from','global','if','import','in','is','lambda','nonlocal','not','or','pass','raise','return','try','while','With','yield']
上面这些关键字都不能作为变量名。| abs() | all() | any() | basestring() | bin() |
| bool() | bytearray() | callable() | chr() | classmethod() |
| cmp() | compile() | complex() | delattr() | dict() |
| dir() | divmod() | enumerate() | eval() | execfile() |
| file() | filter() | float() | format() | frozenset() |
| getattr() | globals() | hasattr() | hash() | help() |
| hex() | id() | input() | int() | isinstance() |
| issubclass() | iter() | len() | list() | locals() |
| long() | map() | max() | memoryview() | min() |
| next() | object() | oct() | open() | ord() |
| pow() | print() | property() | range() | raw_input() |
| reduce() | reload() | repr() | reversed() | zip() |
| round() | set() | setattr() | slice() | sorted() |
| staticmethod() | str() | sum() | super() | tuple() |
| type() | unichr() | unicode() | vars() | xrange() |
| Zip() | __import__() | apply() | buffer() | coerce() |
| intern |
注意:在 Python 2.x 中,print 是关键字而不是函数。上面这些内置函数(如 unicode())只是 Python 2.x 的内置函数,为了保证 Python 程序具有更好的兼容性,程序也不应该使用这些内置函数的名字作为标识符。
版权说明:Copyright © 广州松河信息科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州松河信息科技有限公司 版权所有