Two values from one input in python?

前端 未结 18 2251
小鲜肉
小鲜肉 2020-11-28 03:46

This is somewhat of a simple question and I hate to ask it here, but I can\'t seem the find the answer anywhere else: is it possible to get multiple values from the user in

18条回答
  •  囚心锁ツ
    2020-11-28 04:10

    if we want to two inputs in a single line so, the code is are as follows enter code here

    x,y=input().split(" ")
    
    print(x,y)
    

    after giving value as input we have to give spaces between them because of split(" ") function or method.

    but these values are of string type if to perform some arithmetic operations we have to convert the type of x,y are as follows int(x),int(y)

    we can do this also with the help of list in python.enter code here

    list1=list(map(int,input().split()))
    print(list1)
    

    this list gives the elements in int type

提交回复
热议问题