Python int input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python int input

How can we get 2 seperate integers when they are given in a single line seperated by space using input() function Eg. 2 4 I want to take this input as a=2 and b=4

8th Jul 2020, 8:12 AM
Some Name
Some Name - avatar
3 Answers
+ 4
inp = input("").split(" ") a = int(inp[0]) b = int(inp[1])
8th Jul 2020, 8:16 AM
Arnesh
Arnesh - avatar
+ 2
a, b = list(map(int, input().split()))
8th Jul 2020, 8:28 AM
Slick
Slick - avatar
+ 1
# First Step You Get (input) and (spilt) Number # spilt() => Method Take (separator as string, maxsplit as int) and Put items in list[] my_input = input("Enter Number: ").split() # Second step my_input = ['number_1', 'number_2'] # You assign Two Number by Zero Index Based to Variables a = int(my_input[0]) b = int(my_input[1])
8th Jul 2020, 8:50 AM
Hesham Saeed Sharawy
Hesham Saeed Sharawy - avatar