The input() function allows a script to ask a question and wait for the person using it to answer.
Understanding the Concept
A prompt should clearly describe what to enter. Python returns the reply as a string, and you can store it under a descriptive variable name. Nothing is displayed automatically after input unless you print another message. Programs that require interactive input wait at this point, so the behavior is different from a script with only fixed values.
When and Why You Would Use This
Try entering a common name, a name containing spaces, and an empty line. Notice that Python does not check whether the input is a real name. Validation is a separate step.
Practical Example
person_name = input("What should I call you? ")
print("Nice to meet you,", person_name)
Understanding the Example
The prompt appears first. When the user enters Jordan, the output becomes Nice to meet you, Jordan. The variable stores exactly the input text unless you deliberately clean or transform it.
Example Output
What should I call you? Nice to meet you, 24
Try It Yourself
Ask for both a first name and a last name, then display a combined full name.
Common Beginner Mistakes
- Expecting input() to automatically convert digits to integers.
- Forgetting to use print() for the follow-up response.
- Using an unclear prompt so the person does not know what information is needed.
Key Takeaways
- input() waits for text from the user.
- The returned value is a string.
- Use a clear prompt and an explicit output message.