Python基础:input()输入

input()的类型是str

代码示例

# 输入的都是字符串
a = input("请输入123:")
print(a, type(a))

# 可以分割输入
a, b = input("请输入12 34:").split()
print(a, type(a))
print(b, type(b))

# 通过这种方式,输入的就可以是int了
a = int(input("请输入整型数字:"))
print(a, type(a))

# 一次输入多个int型
a, b, c = map(int, input("请输入1 2 3,中间用空格隔开:").split())
print(a, b, c)
print(type(a), type(b), type(c))

控制台输出

请输入123:123
123 <class 'str'>
请输入12 34:12 34
12 <class 'str'>
34 <class 'str'>
请输入整型数字:4556
4556 <class 'int'>
请输入1 2 3,中间用空格隔开:1 2 3
1 2 3
<class 'int'> <class 'int'> <class 'int'>

进程已结束,退出代码0
posted @ 2022-05-16 12:21  孤舟浮岸  阅读(855)  评论(0)    收藏  举报