Python 内建函数 - input([prompt])

Python的input()函数允许指定提示并从用户接收输入,返回字符串并去除末尾换行。当遇到EOF时会抛出EOFError。如果已加载readline模块,input()将启用行编辑和历史功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Manual

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example:

>>>
>>> s = input('--> ')  
--> Monty Python's Flying Circus
>>> s  
"Monty Python's Flying Circus"

If the readline module was loaded, then input() will use it to provide elaborate line editing and history features.

直译

如果出现prompt参数,它将不后缀换行符写入到标准输出。随后函数根据输入读取一行,将它转化为字符串(去掉尾缀换行符),并返回该值。当读入发生EOF时,引发EOFError。例如:

>>>
>>> s = input('--> ')  
--> Monty Python's Flying Circus
>>> s  
"Monty Python's Flying Circus"

如果加载readline模块,那么input()将会使用它来提供详细的行编辑和历史特征。

拓展阅读

readline

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值