Python关键字

2024-04-26 18:57:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我在网上找到了所有Python关键字及其作用的列表,但是我只能找到这些关键字的列表,而没有解释它们的作用。示例:http://docs.python.org/release/2.3.5/ref/keywords.html。所以基本上,如果我想知道什么是关键字,我必须在网上查找。虽然这不是什么麻烦,但我相信一定有一个来源,所有这些信息已经被组合起来,加快关键字学习过程。在

所以我想知道是否有人可以介绍我到一个网站,我可以找到所有这些信息。在

谢谢!在


Tags: orgref信息http示例docs列表release
3条回答

python interpreter提示符中:

>>> 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”,然后按enter键。在

另外,如果您需要有关当前运行的python版本的关键字的信息(例如,yield是python版本中的关键字吗?),这是keyword module

^{pr2}$

根据您的Python发行版是否安装了文档,您可以通过Python解释器中的交互式帮助菜单直接访问关键字信息:

>>> help()

Welcome to Python 2.7!  This is the online help utility.

...

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> and
Boolean operations
******************

...

The expression ``x and y`` first evaluates *x*; if *x* is false, its
value is returned; otherwise, *y* is evaluated and the resulting value
is returned.

奇怪的是,这是谷歌搜索python keywords and explanations上的first result。在

相关问题 更多 >