首页 › 参考手册 › 内置函数 › input()

Python input() 函数

描述

从标准输入读取一行文本(不含末尾换行符)。如果给出 prompt,会先输出提示信息。返回值总是字符串。

语法

input([prompt])

参数

参数说明
prompt提示文字,可选

返回值

字符串

实例

# 在交互环境中运行:
# name = input("你的名字:")
# age = int(input("你的年龄:"))
print("input() 返回的总是字符串,需要数字时用 int() 或 float() 转换")
以上实例输出结果为:
input() 返回的总是字符串,需要数字时用 int() 或 float() 转换