input()
function
The input() function pauses your program and waits for the user to enter some text. Once Python receives the user’s input, it stores it in a variable to make it convenient for you to work with.
For example, the following program asks the user to enter some text, then displays that message back to the user:
name = input("Please enter your name: ")
print("Hello, " + name + "!")
The input() function takes one argument: the prompt, or instructions, that we want to display to the user so they know what to do. In this example, when Python runs the first line, the user sees the prompt Tell me something, and I will repeat it back to you: . The program waits while the user enters their response and continues after the user presses enter. The response is stored in the variable message, then print(message) displays the input back to the user:
Please enter your name: Eric
Hello, Eric!
Reference
- Python Crash Course (2nd Edition) : A Hands-On, Project-Based Introduction to Programming
- Learning Python