无法将输入作为整数元组(使用一行代码)

unable to take input as a tuple of integers( with one line of code)

我希望用户在表格 a,b 中输入 并将其作为 (a,b) 其中 a,b 是整数

我试过了

c = tuple(int((input("enter tup").split(",")))

我理解为什么这是 error.The 我能够做到这一点的唯一方法是

 c = (input("enter tup").split(",")
 c = [int(x) for x in c]
 c = tuple(c)

.split() 创建一个列表,不需要在第二行创建的中间列表。既然你说你是专门找单线的,你可以这样做:

c = tuple(int(x) for x in (input("enter tup").split(",")))
print(c)

备用:

c = tuple(map(int, input("enter tup").split(",")))
print(c)

这是您的一个班轮代码:

c = tuple(map(int ,input("enter tuple").split()))