how to take two inputs in one line in python?

Rate this post

Today, We want to share with you how to take two inputs in one line in python?.In this post we will show you Python Input | How To Take Multiple Inputs in Python in Single line, hear for how to take unknown number of inputs in python? we will give you demo and example for implement.In this post, we will learn about how to skip a line in python with an example.

Taking multiple inputs from user in Python

  • Using split() method
  • Using List comprehension

Using split() method :

Example 1:

# Python program showing how to
# multiple input using split

# picking two inputs at a time
x, y = input("Set a two value: ").split()
print("Total List of gents: ", x)
print("Total List of ladise: ", y)
print()

# picking three inputs at a time
x, y, z = input("Set a three value: ").split()
print("Total no of members: ", x)
print("Total List of gents is : ", y)
print("Total List of ladise is : ", z)
print()

# picking two inputs at a time
a, b = input("Set a two value: ").split()
print("First no is {} and second no is {}".format(a, b))
print()

# picking multiple inputs at a time 
# and type casting using list() function
x = list(map(int, input("Set a multiple value: ").split()))
print("List of members: ", x)

Using List comprehension :

# Python program showing
# how to take multiple input
# using List comprehension

# picking two input at a time
x, y = [int(x) for x in input("Set two value: ").split()]
print("First Total List is: ", x)
print("Second Total List is: ", y)
print()

# picking three input at a time
x, y, z = [int(x) for x in input("Set three value: ").split()]
print("First Total List is: ", x)
print("Second Total List is: ", y)
print("Third Total List is: ", z)
print()

# picking two inputs at a time
x, y = [int(x) for x in input("Set two value: ").split()]
print("First no is {} and second no is {}".format(x, y))
print()

# picking multiple inputs at a time 
x = [int(x) for x in input("Set multiple value: ").split()]
print("Total List of list is: ", x) 

how to input multiple integers in python?

Example 1

x,y=map(int,input().split())#you can change the int to specify or intialize any other data structures
print(x)
print(y)

Example 2: python input .split()

# picking two inputs at a time 
x, y = input("Set a two value: ").split() 
print("Total List of gents: ", x) 
print("Total List of ladise: ", y) 
print() 

Free Live Chat for Any Issue

Example 3: python multiple inputs

# Python program showing how to 
# multiple input using split 
  
# picking two inputs at a time 
x, y = input("Set a two value: ").split() 
print("Total List of gents: ", x) 
print("Total List of ladise: ", y) 
print() 
  
# picking three inputs at a time 
x, y, z = input("Set a three value: ").split() 
print("Total no of members: ", x) 
print("Total List of gents is : ", y) 
print("Total List of ladise is : ", z) 
print() 
  
# picking two inputs at a time 
a, b = input("Set a two value: ").split() 
print("First no is {} and second no is {}".format(a, b)) 
print() 
  
# picking multiple inputs at a time  
# and type casting using list() function 
x = list(map(int, input("Set a multiple value: ").split())) 
print("List of members: ", x) 

Download

I hope you get an idea about “python 3” input multiple lines.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.