Two values from one input in python?

前端 未结 18 2187
小鲜肉
小鲜肉 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 03:57

    If you need to take two integers say a,b in python you can use map function.
    Suppose input is,

    1
    5 3
    1 2 3 4 5
    

    where 1 represent test case, 5 represent number of values and 3 represents a task value and in next line given 5 values, we can take such input using this method in PYTH 2.x Version.

    testCases=int(raw_input())
    number, taskValue = map(int, raw_input().split())
    array = map(int, raw_input().split())
    

    You can replace 'int' in map() with another datatype needed.

提交回复
热议问题