python的关键字有哪些

anonymity
anonymity 原创
2019-06-11 11:20:51 8278浏览

在python中若想查询python中有哪些关键字。

可以先导入keyword模块

import keyword #导入关键字模块
print(keyword.kwlist) #查询所有关键字

查询结果:

['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']

如果将关键字作为标识符,则会出现以下报错:

and= [1,2,1,3]
print(and)
  File "E:/Selenium_Study/111.py", line 34
    and= [1,2,1,3]
      ^
SyntaxError: invalid syntax

以上就是python的关键字有哪些的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。