Python input() Function
Python input() Function
Python input() function allows the user to provide input to the program. The user can provide the input values to the program at run time.
input() Function
In Python, the built-in function input() receives input from the keyboard. It waits for the input till you enter some value from the keyboard, followed by the Enter key, and returns the entered value as a string.
Basic Syntax
The basic syntax of the input() function is as follows:
input([user_prompt])
user_prompt is optional. We can add if we wish to display a message to the user
on the screen.
For example, the input() function can be used as follows.
>>>number=input(“Enter a number = “)
Enter a number = 79
>>>number
‘79’
Here, we can see that the entered value 79 is a string, not a number. We can use int() or float() functions to convert this into a number.
>>int(number)
79
>>>float(number)
79.0
Examples
name=input(“Enter your name:”)Â # Receive a string value
The input() function returns the entered value as a string, so to receive an integer/float value from the user, we need to convert the value returned from the input() function into an integer with the help of the built-in function int().
age=int(input(“Enter your age:”))Â # Receive an integer value
Similarly, we can use the float() built-in function for float.
weight=float(input(“Enter your weight:”))Â # Receive float value
—
Python Tutorials
Python Tutorial on this website can be found at:
More information on Python is available at the official website: