pythoninputintegertuplestypecasting-operator

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


i want the user to input in form a,b and take that as (a,b) where a,b are integers

I tried

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

i understand why this is a error.The only way i am able to do this is

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

Solution

  • .split() creates a list, and the intermediate list being created on the second line isn't necessary. Since you said you were looking for a one-liner specifically, you can do the following:

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