input() Functioninput()?The input() function in Python is used to get input from the user.
It pauses your program and waits for the user to type something and press Enter.
The basic syntax is simple:
This will store whatever the user types into variable_name.
Let’s say hello to the user.
If the user types “Alice” and presses Enter, the output will be:
Hello, Alice!
prompt ArgumentYou can provide a message to the user, called a prompt.
This is much more user-friendly!
The input() function always returns a string.
Even if the user types a number, it’s treated as a string.
If the user enters 25, the output will be:
<class 'str'>
To use the input as a number, you need to convert it.
Use int() for integers and float() for decimal numbers.
A simple calculator to add two numbers.
Let’s combine what we’ve learned.
TypeError when doing math.input() gets user input.prompt string.int(), float(), etc. to convert the type.Happy coding!