How to read an array of integers from single line of input in python3

前端 未结 4 757
情深已故
情深已故 2020-11-30 09:37

I want to read an array of integers from single line of input in python3. For example: Read this array to a variable/list

1 3 5 7 9

What I

4条回答
  •  既然无缘
    2020-11-30 09:59

    Edit: After using Python for almost 4 years, just stumbled back on this answer and realized that the accepted answer is a much better solution.

    Same can be achieved using list comprehensions:
    Here is example on ideone:

    arr = [int(i) for i in input().split()]

    If you are using Python 2, you should use raw_input() instead.

提交回复
热议问题