Loading...

Python Input and Output

print already sends a line out. input waits for a line to come in. You type, then press Enter. guest = input() stores that line as text under the name guest. print(guest) writes the same text back.

Read one line, then write it back

python
guest = input()
print(guest)

Type lida and press Enter. The output is lida. The name guest holds the text lida. Nothing numeric happened. The line you typed is text, the same kind print("lida") already showed.

The prompt is shown, not stored

Put text inside input and that text appears while the program waits. It is a label for you. It is not part of the line that gets stored. input("Guest: ") shows Guest: and then waits. If you type tea, guest holds tea. It does not hold Guest: tea.

A label, then the typed line

python
guest = input("Guest: ")
print(guest)

You see Guest: on the waiting line. You type tea and press Enter. The next line is tea. print wrote what was stored, not the label.

The three rows are the same program with a different line typed each time. guest = input() then print(guest).

📊 What comes back

You type guest holds print writes
lida lida lida
tea tea tea
Enter alone empty text a blank line

Enter alone stores empty text

If you press Enter without typing, the stored text is empty. print still runs. It writes a blank line. Empty is not the word empty, and it is not a missing name. The name guest exists. It holds no characters.

Digits you type are still text

Type 3 and guest holds the character 3. This page does not add, and it does not turn that character into a number. The next page is numbers. Until then, 3 from input is text.

Check yourself

  1. Type lida. guest = input() then print(guest) writes lida.
  2. input("Guest: ") shows the label. The stored line is only what you type after it.
  3. Enter alone stores empty text, and print writes a blank line.
  4. Typing 3 stores text, not a number.
  5. The label Guest: is not inside guest.

Misses

  • Expecting Guest: tea when you typed only tea
  • Thinking Enter alone means the name was never stored
  • Treating a typed 3 as a number you can add on this page
  • Forgetting Enter, so the program is still waiting
  • Printing the label and calling that the typed line

Keep

  • input() waits. You type a line and press Enter. guest = input() stores that line as text.
  • print(guest) writes the stored text back. Type lida, see lida.
  • input("Guest: ") shows a label. The label is not stored. Type tea, and guest holds tea.
  • Enter alone stores empty text. print writes a blank line.
  • A typed 3 is still text. Numbers are the next page.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
6
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 Instructions

  • Read each question carefully
  • Select the best answer for each question
  • You can retake the quiz as many times as you want
  • Your progress will be shown at the top