终端中的 Python:如何表示 for 循环的结束?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42681688/
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
Python in terminal: how to signify end of for loop?
提问by kgf3JfUtW
Say I want to print 0
through 9
.
说我想0
通过9
.
I type in for i in range(10): print(i)
, press enter, and terminal shows ...
, waiting for further statements.
我输入for i in range(10): print(i)
,按enter,终端显示...
,等待进一步的陈述。
So I have to press enteragain to have the numbers printed.
所以我必须enter再次按下才能打印数字。
>>> for i in range(10): print(i)
...
How can I have the number printed without having to press entertwice?
如何无需按enter两次即可打印数字?
回答by alexis
Just type the two returns and move on. But since you ask, this only needs one Enter:
只需键入两个返回并继续。但是既然你问了,这只需要一个Enter:
exec("for i in range(10): print(i)")
回答by Paarmita
"alt+enter" I was working in ipython and facing the same problem as yours. upon trying various combinations from keyboard, this one finally worked
“alt+enter”我在 ipython 中工作并面临与您相同的问题。在尝试各种键盘组合后,这个终于奏效了