python如何输入回车

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

raw_input就是从标注输入读取输入,输入的是什么就是什么。

文档解释:

The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

复制代码
stopword = '' # 输入停止符
str = ''
for line in iter(raw_input, stopword): # 输入为空行,表示输入结束
  str += line + '\n'
 
# print (str)  #测试用
相关推荐
vivo互联网技术41 分钟前
ICLR2026 | 视频虚化新突破!Any-to-Bokeh 一键生成电影感连贯效果
人工智能·python·深度学习
敏编程2 小时前
一天一个Python库:virtualenv - 隔离你的Python环境,保持项目整洁
python
喝茶与编码4 小时前
Python异步并发控制:asyncio.gather 与 Semaphore 协同设计解析
后端·python
zone77394 小时前
003:RAG 入门-LangChain 读取图片数据
后端·python·面试
用户8356290780514 小时前
在 PowerPoint 中用 Python 添加和定制形状的完整教程
后端·python
用户962377954485 小时前
🚀 docx2md-picgo:Word 文档图片一键上传图床工具
python·markdown
zone77391 天前
001:简单 RAG 入门
后端·python·面试
F_Quant1 天前
🚀 Python打包踩坑指南:彻底解决 Nuitka --onefile 配置文件丢失与重启报错问题
python·操作系统
允许部分打工人先富起来1 天前
在node项目中执行python脚本
前端·python·node.js