Home >Backend Development >Python Tutorial >What are the keywords of python

What are the keywords of python

anonymity
anonymityOriginal
2019-06-11 11:20:519310browse

In python, if you want to query what keywords are in python.

What are the keywords of python

You can import the keyword module first

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

Query results:

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

If you use keywords as identifiers, the following error will appear:

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

The above is the detailed content of What are the keywords of python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn