In this tutorial, you will go through the python built-in input() function to ask for input from the uses.
Sometimes we want to ask for some input from the users to process that value. In this guide, we will see some examples to understand the python input function.
Python input function
Python input function is a Python built-in function that is used to ask input from the users. This is function is most used by python programmers.
Syntax
The syntax of python input() function is:-
input(prompt)
Parameter
input function in python accepts one parameter.
- prompt – A String, representing a default message before the input.
Python input example
Here we will take some examples to understand the input function.
Example 1:
name = input('Please enter your name:- ')
print(f"Your name is:- {name}")
Output
Please enter your name:- Vishvajit
Your name is:- Vishvajit
Example 2:
In this example we will ask 5 value from the user one by one and store them into python list.
#Empty list
value = []
for i in range(1, 6):
value.append(input(f"Enter {i} value:- "))
print("List is:- ", value)
Output
Enter 1 value:- 12
Enter 2 value:- 10
Enter 3 value:- Vishvajit
Enter 4 value:- 40
Enter 5 value:- 50
List is:- ['12', '10', 'Vishvajit', '40', '50']
Conclusion
So, Here you have learned the Python input function to take input from the user to process that value.
The input function in python is the most useful function to ask for any value from the user.
If you like this article, please share and keep visiting for further python built-in functions tutorials.
Python built-in functions
For more information:- Click Here