Learn how to handle Python errors and exceptions effectively. Fix common Python errors like SyntaxError, TypeError, and NameError with practical examples.
input()
?The input()
function in Python is used to take user input from the keyboard. It allows a program to interact with users by asking for information.
variable_name = input("Prompt message")
Prompt message
: A string displayed to the user before they enter input.variable_name
: The variable where the userβs input is stored.Basic Example
name = input("Enter your name: ")
print("Hello, " + name + "!")
input("Enter your name: ")
displays the message βEnter your name: β and waits for the user to type something.name
.print("Hello, " + name + "!")
displays a greeting message with the userβs name.By default, input()
returns a string. If you need a number, you must convert it using int()
or float()
.
age = int(input("Enter your age: "))
print("In 5 years, you will be", age + 5)
int(input(...))
converts it into an integer.