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 程式具有更好的相容性,程式也不應該使用這些內建函數的名字作為識別符號。