欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

python的关键字有哪些

程序员文章站 2022-03-19 15:40:56
...
在python中若想查询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的关键字有哪些的详细内容,更多请关注其它相关文章!

相关标签: Python