如何在 Python Shell 中换行?
我想在控制台上写下以下两行:
x = 3
print x**5
但是当我输入 x = 3 时,我按 Enter 键,然后它就会执行分配。如何让它在输入第二行后才执行?
I want to write the following two lines on the console:
x = 3
print x**5
But when I type x = 3
, I press enter, it then executes the assignment. How to get it to execute only after typing the second line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用 Ctrl-J 键序列而不是 Enter 键来获得简单的换行符和缩进,而无需 IDLE 开始解释代码。
您可以在
选项->配置
IDLE 菜单下找到其他按键序列,使 IDLE 更易于用于此类学习。Use the Ctrl-J key sequence instead of the Enter key to get a plain newline plus indentation without having IDLE start interpreting your code.
You can find other key sequences that make IDLE easier to use for this type of learning under the
Options->Configure
IDLE menu.以
;\
结束行:End lines with
;\
:每行后面加上 \ 标记并按 Enter 键
after every line put \ mark and press enter
要对语句组进行编码,
;\
将起作用将打印两个列表
其中,对于
Indentation
语句,您需要:\
将显示所有列表中的元素
To code group of statements,
;\
will workWill print both the lists
Where as, for
Indentation
statement, you need:\
Will show all the elements in the list
应该有帮助,但它在 IDLE 中的执行方式并不重要。
should help, but it doesnt matter that its executed the way it is in IDLE.
只需打开一个新文件:文件>新窗口。您可以通过单击“运行”>“来运行它”运行模块。
Just open a new file: File > New window. You can run it by clicking run > run module.
该行末尾的
"\"
行对我有用。在 Windows 10 cmd 中。编辑:我还注意到你必须与其使用保持一致,否则你仍然会遇到语法错误
the
"\"
line at the end of the line works for me. in windows 10 cmd.Edit: I've also noticed that you have to be consistent with its use, other wise you still get syntax error
使用 F2 键进入编辑器模式。根据您的终端配置,这将使您进入 vim 或 nano。您可以编辑一段代码,然后退出编辑器模式,以使用您的代码和任何换行符返回 ipython cli。
Go into editor mode with the F2 key. Depending on your terminal config this will put you in vim or nano. You can edit a snippet of code and then exit editor mode to get back to the ipython cli with your code and any newlines.