为了账号安全,请及时绑定邮箱和手机立即绑定

python中如何将回车作为输入内容?

python中如何将回车作为输入内容?

呼啦一阵风 2019-04-11 11:07:29
python中如何将回车作为输入内容
查看完整描述

3 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

Python默认遇到回车的时候,输入结束。所以我们需要更改这个提示符,在遇到空行的时候,输入才结束。

123456stopword = '' # 输入停止符str = ''for line in iter(raw_input, stopword): # 输入为空行,表示输入结束  str += line + '\n' # print (str)  #测试用


查看完整回答
反对 回复 2019-04-16
?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

raw_input就是从标注输入读取输入,输入的是什么就是什么。
文档解释:
The function then reads a line from input, converts it to a string (stripping a
trailing newline), and returns that.

查看完整回答
反对 回复 2019-04-16
  • 3 回答
  • 0 关注
  • 5730 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信