python關(guān)鍵字有哪些?
本文教程操作環(huán)境:windows7系統(tǒng)、Python3.9.1,DELLG3電腦。
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關(guān)鍵字列表
>>>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、判斷字符串是否含關(guān)鍵字
>>>keyword.iskeyword('and')
True
>>>
>>>keyword.iskeyword('has')
False
好啦,以上就是關(guān)于關(guān)鍵字查看的全部內(nèi)容了,感興趣的小伙伴可以進行設(shè)置查看哦~更多Python學習教程請關(guān)注IT培訓機構(gòu):千鋒教育。