正如标题所说,我需要从一个控制台输入影响多个变量的值。
我想从输入行一次存储3个数字,如下所示:
-number1-space -number2空间,number3-
现在我这样做:
numbers = input("Enter three numbers separated by spaces: ")
nb1 = int(numbers.split()[0])
nb2 = int(numbers.split()[1])
nb3 = int(numbers.split()[2])
但是如果你能做到这样的话,我不会感到惊讶:
nb1, nb2, nb3 = input("Enter three numbers separeted by spaces: ",? ,?)
用实际工作的代码替换问号。
所以如果你知道更好的方法,我会感激不尽。
答案 0 :(得分:1)
msg = "Enter three numbers separated by spaces: "
n1, n2, n3 = (int(n) for n in input(msg).split())