Python Input
Python Input
In Python, “input” is important, as it allows users to interact with the program in the form of informational inputting. When executed, the system stops at the “input” line and waits until a user input is provided.
To initiate user input, the programming language uses the keyword “input”, followed by brackets. By default, the output of such execution is in the type of string (text).
Below is an example.
age = input("What is your age?: ") # For example, user inputs 26. print(age) # Output: 26
Although the case above refers to integers (numbers), “input” still produces the number in the string type.
Python can change the type of output with one of the specific type keyword.
age = input("What is your age?: ") # For example, user inputs 26. print(age) print(type(age)) # Output: 26 (with the type "str")
# Input with int() declaration age = int(input("What is your age?: ")) # For example, user inputs 26. print(age) print(type(age)) # Output: 26 (with the type "int")

Next: Python Functions