Python · Stage 2 – Doing Things with Values · Lesson 17 of 50

Getting User Input

Pause a program and collect text typed by the user.

name = input("What is your name? ")
Line-by-line explanation
  1. input displays a question and waits.
  2. The text inside brackets is the question.
  3. The user types an answer and presses Enter.
  4. name stores that answer as a string.

input() always returns a string, even if the person types digits.

age_text = input("Age: ")
Line-by-line explanation
  1. The prompt Age: appears.
  2. The user types an answer.
  3. age_text stores text such as "12".