Python包含一系列关键字和内置函数,给变量命名时,知道这些关键字和内置函数非常重要。变量名不能是关键字,也不应该是内置函数。
1、Python中的关键字
False | None | True |
and | as | assert |
break | class | continue |
def | del | elif |
else | secept | finnally |
for | from | global |
if | import | in |
is | llambda | nonlocal |
not | or | pass |
raise | return | try |
while | with | yield |
其中关键字的具体含义和用法放在文末。
2、Python中的内置函数
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() | round() |
set() | setattr() | slice() | sorted() |
staticmethod() | str() | sum() | super() |
tuple() | type() | unichr() | unicode() |
vars() | xrange() | zip() | __import__() |
apply() | buffer() | coerce() | intern() |
其中内置函数的用法也附在文末。