python3 input() 用来获取控制台的输入。
input() 将所有输入作为字符串看待,返回字符串类型。
函数语法
input([prompt])
参数说明:
prompt: 可选,字符串,可作为一个提示语。
实例
>>>a = input("input:")
input:123
>>> type(a)
<type 'str'> # 字符串
>>> a = input("input:")
input:hello
>>> type(a)
<type 'str'> # 字符串
b = int(input()) #类型转换
123
type(b)
<type 'int'>
本文介绍了Python中input()函数的基本用法及其如何从控制台接收用户输入,并解释了它总是返回字符串类型这一特性。同时,文章还展示了如何通过内置的类型转换函数如int()来改变输入数据的类型。
582

被折叠的 条评论
为什么被折叠?



