0

1.2Python交互式解释器

Posted by 撒得一地 on 2015年11月10日 in python教程

在window下,当启动python时,会出现和下面相似的提示:

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:37:12) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

注意:这里解释器的准确外观和错误信息都取决于当前python版本。

python交互式解释器和linux的shell很相似,感觉瞬间进入了"黑客殿堂"—这是你控制计算机的第一步。

运行第一个python语句,输入下面的命令看看它是否能正常工作:

>>> print('hello world!')

当你按下回车键,会有下面的输出:
hello world!

注意:如果熟悉了其它计算机语言,可能会习惯每个语句以分号来结束。不过,Python则不用,一行就是一行,不管多少。不过可以加上分号,但是不会有任何作用(除非同一行还有更多代码),而且这也不是通行做法。

解释器上的>>>符合是提示符,表示可以在后面写点什么语句来执行。当你按下回车,命令执行成功后,下一行又会出现一个新的提示符。

当你在提示符后输入无效语句,就会提示出错,比如:

>>> for test
  File "<stdin>", line 1
    for test          ^
SyntaxError: invalid syntax

显然,解释器不明白输入为何物,不过解释器能够指出哪里地方出错了。你可以输入help()命令尝试获得帮助,然后输入quit退出帮助。比如:

>>> help()
Welcome to Python 3.3!  This is the interactive help utility.
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.3/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".
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> quit
You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.

总的来说,python还是比较有意思的。

标签:

上一篇:

下一篇:

相关推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注

9 + 0 = ?

网站地图|XML地图

Copyright © 2015-2024 技术拉近你我! All rights reserved.
闽ICP备15015576号-1 版权所有©psz.