multiple input in one line in python|input multiple value |python in hindi|cbse|btech|MCA|BCA
Today we discuss about how to input multiple input using python in one line
There is an easy way of doing this using these inbuilt functions.
a) Using split() function
b) Using input () function
c) Using map () function
d) Using List Comprehension
a) split ()
split( ) function helps us get multiple inputs from the user and assign them to the respective variables in one line. This function is generally used to separate a given string into several sub strings. However, you can also use it for taking multiple inputs. The function generally breaks the given input by the specified separator and in case the separator is not provided then any white space is considered as a separator.
The syntax for using the split function to take multiple inputs is
variable 1, variable 2 = input("Enter what has to be conveyed to the user here"). split()
# for space-separated inputs
variable 1, variable 2 =input("Enter what has to be conveyed to the user here"). split(" , ")
# for comma separated inputs
An example is,
# Python program to take multiple inputs from the user
a, b = input("Enter two of your lucky number: ").split()
print("First lucky number is: ", a)
print("Second lucky number is: ", b)
Output:
Enter two of your lucky number: 7 1
First lucky number is: 7
Second lucky number is: 1
b) input ()
You can take multiple inputs in one single line by using the raw_input function several times as shown below.
#multiple inputs in Python using input
x, y = input("Enter First Name: "), input("Enter Last Name: ")
print("First Name is: ", x)
print("Second Name is: ", y)
Output:
Enter First Name: Arun
Enter Last Name: Sir
First Name is: Arun
Second Name is: Sir
c) map()
map() is another function that will help us take multiple inputs from the user. In general, the syntax for map function is map (fun, iter). Here fun is the function to which the map function passes each iterable.
Syntax for multiple input using map()
variable 1, variable 2, variable 3 = map(int,input().split())
An example to take integer input from the user.
#multiple inputs in Python using map
x, y = map(int, input("Enter two values: ").split())
print("First Number is: ", x)
print("Second Number is: ", y)
Output:
Enter two values: 7 1
First Number is: 7
Second Number is: 1
An example to take string input from the user.
#multiple inputs in Python using map
x, y = map(str, input("Enter your first and last name ").split())
print("First Name is: ", x)
print("Second Name is: ", y)
d) List Comprehension
List date types also helps in taking multiple inputs from the user at a time. The syntax for creating a list and storing the input in it is
x, y=[x for x in input("Enter two value: ").split()]
List allows you to take multiple inputs of different data type at a time. The below example will help you understand better.
#multiple inputs in Python using list comprehension
x, y = [x for x in input("Enter your name and age: ").split(",")]
print("Your name is: ", x)
print("Your age is: ", y)
Output:
Enter your name and age:XYZ , 18
Your name is: Xyz
Your age is: 18
Learn Python for Beginners in hindi
https://youtu.be/vsxFigs2Hac
Learn Mathematics for class X in hindi
https://youtu.be/Ssxc5_-BkXQ
If you found this video valuable, give it a like.
If you know someone who needs to see it, share it.
Leave a comment below with your thoughts.
Add it to a playlist if you want to watch it later.
Thanks :)
DISCLAIMER: The information contained on this YouTube Channel and the resources available for download/viewing through this YouTube Channel are for educational and informational purposes only.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «multiple input in one line in python|input multiple value |python in hindi|cbse|btech|MCA|BCA», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.