How to take multiple inputs in Python
We often need to take multiple inputs while programming. In languages like C/C++, we can use scanf to take multiple inputs in one line. But in python, the same can be achieved using
1. Using split() method
2. Using list comprehension
1. Using split() method
split() function helps to take multiple inputs from the user. This function breaks the given input by the specified separator. If a separator is not provided, then white space is considered as the separator.
Syntax: input().split(separator,maxlimit)
#taking two inputs from user a,b = input().split() print(a+" "+b) #taking three inputs x,y,z=input().split(',')
2. Using List comprehension
List comprehension can also used in getting multiple inputs from a user.
# taking multiple inputs at a time a = [int(a) for a in input("Enter values: ").split()]
Subscribe
Login
Please login to comment
0 Discussion