Python关键字

Python2.7环境中,关键字共有31个。

可以通过

1
2
>>> import keyword
>>> print keyword.kwlist

进行查看。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
and
as
assert
break
class
continue
def
del
elif
else
except
exec
finally
for
from
global
if
import
in
is
lambda
not
or
pass
print
raise
return
try
while
with
yield

需要注意,在变量命名的时候 防止使用到关键字!