python关键字有哪些?怎么看?

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

1、keyword模块进行输出查看

Helponmodulekeyword:
NAME
keyword-Keywords(from"graminit.c")
FILE
/usr/lib64/python2.6/keyword.py
DESCRIPTION
Thisfileisautomaticallygenerated;pleasedon'tmuckitup!
Toupdatethesymbolsinthisfile,'cd'tothetopdirectoryof
thepythonsourcetreeafterbuildingtheinterpreterandrun:
pythonLib/keyword.py
FUNCTIONS
iskeyword=__contains__(...)
x.__contains__(y)yinx.
DATA
__all__=['iskeyword','kwlist']
kwlist=['and','as','assert','break','class','continue','def',...

2、得到python关键字列表

>>>keyword.kwlist
['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']

3、判断字符串是否含关键字

>>>keyword.iskeyword('and')
True
>>>
>>>keyword.iskeyword('has')
False
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。