Python 三个箭头 (">>>") 符号是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16420078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What do the three arrow (">>>") signs mean?
提问by Dumle29
So this is probably a dumb question, but I have now been searching for quite some time, and I haven't been able to figure out what they do even though I see them often in source-codes.
所以这可能是一个愚蠢的问题,但我现在已经搜索了很长一段时间,即使我经常在源代码中看到它们,我也无法弄清楚它们是做什么的。
采纳答案by askewchan
You won't see it in source code, it's probably documentation. It indicates an interactive session, and things typed into the 'interpreter' are marked with this. Output is shown without the arrows.
你不会在源代码中看到它,它可能是文档。它表示一个交互式会话,并且输入到“解释器”中的内容都标有此标记。输出显示不带箭头。
In fact, the python documentationoften has a button >>>at the top right of example code to be able to hide the arrows (and output) so that you can copy and paste the code.
实际上,python 文档通常>>>在示例代码的右上角有一个按钮,可以隐藏箭头(和输出),以便您可以复制和粘贴代码。
Shown:
Hidden:
显示:
隐藏:
回答by silvado
'>>>' is the prompt of the interactive Python interpreter, meaning that the interpreter is ready to get Python statements typed in. It's occuring quite often in examples within the documentation of a Python program, in order to show which commands can be used and what will be the result of giving these commands to the interactive interpreter. For example, in a documentation of the printstatement, one could give this example:
“>>>”是交互式 Python 解释器的提示,意味着解释器已准备好输入 Python 语句。它经常出现在 Python 程序文档中的示例中,以显示可以使用哪些命令以及将这些命令提供给交互式解释器会产生什么结果。例如,在print声明的文档中,可以给出以下示例:
>>> print "Hello world."
Hello world.
This would be an actual snippet of a session with the interactive Python interpreter.
这将是交互式 Python 解释器会话的实际片段。
An interesting feature in IPythonis that it ignores leading >>>, meaning that you can copy and paste code from such documentation without needing to remove the leading >>>:
IPython 中一个有趣的特性是它忽略了前导>>>,这意味着您可以从此类文档中复制和粘贴代码而无需删除前导>>>:
In [1]: >>> print "Hello world."
Hello world.
(The prompt in IPython is In [n]:, where nis counting the interactive commands issued.)
(IPython 中的提示是In [n]:,其中n计算发出的交互式命令。)
回答by Bleeding Fingers
Here are some of my findings on >>>and consequently ...complementing the previous answers.
以下是我的一些发现,>>>并因此...补充了之前的答案。
You only see >>>when you are running Python in interactive modeprompting/asking the user for the "next command". Technical details here.
只有>>>在交互模式下运行 Python 时,您才会看到提示/询问用户“下一个命令”。技术细节在这里。
>>>and ...are not written in stone. These are stored in sys.ps1and sys.ps2, and therefore can be changed. Further elaborated here.
>>>并且...不是写在石头上的。这些存储在sys.ps1和 中sys.ps2,因此可以更改。这里进一步阐述。
>>> import sys
>>> sys.ps1 = "$ "
$
Every standard Python has this prompt unless you compile your own Python after changing >>>and ...to what you (sanely) wish to. Apart from that there seems to be a way to change it for all future interactive sessions by changing /usr/lib/python2.7/code.pybut I couldn't find any success with it.
每个标准 Python 都有此提示,除非您在更改后编译自己的 Python>>>并...按照您(理智地)希望的方式编译。除此之外,似乎有一种方法可以通过更改为所有未来的交互式会话更改它,/usr/lib/python2.7/code.py但我找不到任何成功的方法。
回答by Hossam Elshanwy
The >>> prompt is the Python interpreter's way of asking you, “What do you want me to do next?”, and it is called "chevron" prompt
>>> 提示符是 Python 解释器询问您“接下来要我做什么?”的方式,它被称为“雪佛龙”提示符

