我在网上查找了所有Python关键字的列表以及它们的作用,但是我只能找到关键字列表而不解释它们的作用.示例:http://docs.python.org/release/2.3.5/ref/keywords.html.所以基本上,如果我想知道关键字是什么,我必须在网上寻找它.虽然这并不是很麻烦,但我相信必须有一个来源,所有这些信息都已被分组,加快了关键字学习过程.
所以我想知道这里是否有人可以将我推荐到一个我可以找到所有这些信息的网站.
谢谢 !
在python解释器提示符中:
>>> help() [OMITTED LINES FOR BREVITY] To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam". help> keywords Here is a list of the Python keywords. Enter any keyword to get more help. and elif if print as else import raise assert except in return break exec is try class finally lambda while continue for not with def from or yield del global pass help>
现在要获取有关例如break的信息,只需输入"break"然后输入即可.
另外,如果您需要有关当前正在运行的python版本的关键字的信息(例如yield,我的python版本中的关键字?),则有关键字模块:
>>> from keyword import kwlist, iskeyword
>>> 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']
>>> iskeyword("and")
True
Run Code Online (Sandbox Code Playgroud)