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

2025-12-01 0 99,804

 

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

1、keyword模块进行输出查看

Help on module keyword:
NAME
 keyword - Keywords (from "graminit.c")
FILE
 /usr/lib64/python2.6/keyword.py
DESCRIPTION
 This file is automatically generated; please don't muck it up!
 To update the symbols in this file, 'cd' to the top directory of
 the python source tree after building the interpreter and run:
  python Lib/keyword.py
FUNCTIONS
 iskeyword = __contains__(...)
  x.__contains__(y) y in x.
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

好啦,以上就是关于关键字查看的全部内容了,感兴趣的小伙伴可以进行设置查看哦~

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 python基础 python关键字有哪些?怎么看? https://www.zhiup.top/2656.html

相关