windoanvn
windoanvn

Reputation: 15

Read many inputs at the same time in Python

I am making a program that read 2 or more input at the same time. How can I read input that has the form a b? For example: 3 4. I need to read 2 variables: a = 3 and b = 4.

Upvotes: 1

Views: 890

Answers (1)

arshajii
arshajii

Reputation: 129537

You can do something like

a,b = input().split()

For example:

>>> a,b = input().split()
3 4
>>> a
'3'
>>> b
'4'

For reference, see input() and str.split().


If you want a and b to be ints, you can call map() (as is described in the comments):

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

Upvotes: 3

Related Questions