Python中關(guān)鍵詞有多少個?Python中關(guān)鍵詞目前有31個,可以利用Python的內(nèi)置的keyword模塊進行輸出查看。
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',...
得到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']
判斷字符串是否是python的關(guān)鍵字
>>>keyword.iskeyword('and')
True
>>>
>>>keyword.iskeyword('has')
False
以上內(nèi)容為大家介紹了Python培訓之關(guān)鍵字有多少個?,希望對大家有所幫助,如果想要了解更多Python相關(guān)知識,請關(guān)注IT培訓機構(gòu):千鋒教育。