原始输入后的新行

2024-05-03 07:18:42 发布

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

首先,我对编程和python都是新手,所以我提前道歉。在

我试图使用原始输入从用户那里获取输入,但也在努力使代码更简单。在

我最初的想法是:

print "Please give the name of your project."
project_name = raw_input()

这给了我: “请给出您的项目名称。” 试验

为了缩短时间,我改为:

^{pr2}$

这给了我: “请给出你的项目名称。”测试

所以它要求用户在提示后立即输入信息。我想换一条新线路。在


Tags: ofthe代码用户nameprojectinputyour
2条回答

只需在提示中添加新行:

project_name = raw_input("Please give the name of your project.\n")

你可以换一行:

>>> project_name = raw_input("Please give the name of your project.\n")
Please give the name of your project.
myProject
>>> project_name
'myProject'
>>>

在提示字符串中,\n创建一个换行符。在

相关问题 更多 >