因为python的特性,input不可能同行接收多个元素
a, b = input()
"""
输出结果:
a, b = input()
^^^^
ValueError: too many values to unpack (expected 2)
"""
所以要使split函数,将输入的结果分割开来,分别赋值两个变量
a, b = input().split()
print(a, b)
print(type(a))
print(type(b))
"""
输出结果:
1 2
1 2
<class 'str'>
<class 'str'>
"""
这样输出的变量是str类型,我想转换成int类型,但是报错了
a, b = int(input().split())
print(a, b)
"""
a, b = int(input().split())
^^^^^^^^^^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
"""
所以,只能map函数,挨个把元素转换成int类型,然后输出
a, b = map(int, input().split())
print(a, b)
print(type(a))
print(type(b))
"""
1 2
1 2
<class 'int'>
<class 'int'>
"""