Taking Multiple Input from user in Python

Taking Multiple Input from user in Python


Taking Multiple Input from user in Python



We can take multiple inputs In python from the user In a single line
We can do so by two methods:
·        Using split() method
·        Using List comprehension


Using split() method:

This function breaks the multiple inputs by the separator, if the separator is not provided by the user then any white space is a separator. Generally split() function splits the given string by the user, But we can use as taking multiple inputs.



This is the syntax :

 input().split(separator, maxsplit)



Here is the given code for clearing your concept:


python,anaconda python,opencv,matplotlib,python online,python programming,python list,learn python,scikit learn,python ide


output:


python,anaconda python,opencv,matplotlib,python online,python programming,python list,learn python,scikit learn,python ide




Using List Comprehesion: 

List comprehension is an elegant way to define and create list in Python. We can create lists just like mathematical statements in one line only, very simple and easy syntax ,It is also used in getting multiple inputs from a user.


here is the explanation :


python,anaconda python,opencv,matplotlib,python online,python programming,python list,learn python,scikit learn,python ide





output :


python,anaconda python,opencv,matplotlib,python online,python programming,python list,learn python,scikit learn,python ide



Note : 


The above examples take input separated by spaces. In case we wish to take input separated by comma (, ), we can use following:


# taking multiple inputs at a time separated by comma
x = [int(x) for x in input("Enter multiple value: ").split(",")]
print("Number of list is: ", x) 












 #python for data science course free
 #learn python for data analysis free
 #learn python free
 #best sites to learn python
 #micropython
 #python for data science
 #data science from scratch
 #micropython esp32
 #machine learning using python
 #matplotlib
 #python 3
 #scikit learn
 #tkinter
 #python training
 #python data analysis
 #best python tutorial
 #python classes near me
 #learn python for beginners
 #python online training
 #django course
 #advanced python course
 #python course fees
 #introduction to data science in python
 #free python tutorial
 #learn python basics
 #python study
 #python and ai
 #python computer science
 #learn python step by step
 #best course to learn python
 #learn python with projects
 #python artificial intelligence tutorial
#python
 #anaconda 
#opencv
#matplotlib
#python online
#python programming
#python list
#learn python
#scikit learn
#python ide














Post a Comment

1 Comments

  1. appreciate your work.Please continue providing your valuable knowledge.It is helping me a lot. :)

    ReplyDelete

If you have any doubt, Please let me know.