How to input 2 integers in one line in Python?

后端 未结 2 1724
旧时难觅i
旧时难觅i 2020-12-18 21:50

I wonder if it is possible to input two or more integer numbers in one line of standard input. In C/C++ it\'s easy:

C++:

相关标签:
2条回答
  • 2020-12-18 22:06

    Split the entered text on whitespace:

    a, b = map(int, input().split())
    

    Demo:

    >>> a, b = map(int, input().split())
    3 5
    >>> a
    3
    >>> b
    5
    
    0 讨论(0)
  • 2020-12-18 22:19

    If you are using Python 2, then the answer provided by Martijn does not work. Instead,use:

    a, b = map(int, raw_input().split())
    
    0 讨论(0)
提交回复
热议问题