How to take a line input in python Consider I need to take input in a line consisting integers seperated by spaces I want to give 5 6 and store them in a and b
a=input()
b=input()
If I take in above format, it takes only when I press enter
Its very simple
j,k=input().split(" ")
j=int(j)
k=int(k)
input().split() does the same thing you don't need " "j,k = map(int, input().split())split(); if the user types 3 4 with two spaces, it will probably be surprising to get a ValueError: too many tuple values to unpack (expected 2)…
inputfunction "… reads a line from input …", which is why you have to hit enter after for each value. To accept multiple values on a line, you want to justinputonce, then parse the line (which is easy, as @saliesh shows).raw_input, and to explain why).