Interaction with the user

Module 2 · Interaction with the user · Lesson 1 of 6

The input() function

Your programs have only talked at people so far. The input() function lets them listen back. When Python reaches an input(), it pauses and waits for the user to type a line and press Enter — and whatever they typed becomes the function's result.

name = input("What's your name? ")
What's your name? Ada
name
"Ada"

On its own, input() just waits silently — not very friendly. Give it a prompt as an argument and it shows that text first, so the user knows what you're asking for: input("Your name? ").

Run it yourselfruns in your browser · Python
main.py

Run it — a box will pop up asking for your input. Type a name and watch the program carry on with it. (On your own machine the program waits right there in the terminal until you type.) Almost always you'll store the result in a variable, as we did with name, so you can use it afterwards.