How to enter multiple values at once with the input function

Use the split() function

The input function inputs are all string types, so the input string can be divided by the split() function, and multiple parameters can be input at one time.
Program example:

a,b=input("请依次输入横纵坐标,用空格分开,输入结束后点击enter键: ").split()
print(a,b)

Note that the two values ​​of a and b obtained here are both string types.
If you want to get int type or float type, you need to convert again.

Use the map() function

If the value type you want to get directly is int or float, you can use the map function directly.
The code example is as follows:

a,b =map(int,input("请依次输入横纵坐标,用空格分开,输入结束后点击enter键: ").split())
print(a,b)
print(type(a))

After running, you can see that the result type obtained by map is int type

Guess you like

Origin blog.csdn.net/ximu__l/article/details/129350080