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:
output:
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 :
output :
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)
#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 |
#anaconda
#opencv
#matplotlib
#python online
#python programming
#python list
#learn python
#scikit learn
#python ide
1 Comments
appreciate your work.Please continue providing your valuable knowledge.It is helping me a lot. :)
ReplyDeleteIf you have any doubt, Please let me know.