Why print("2 + 2") Doesn't Print 4 in Python

Printing values Python works out — and why quotes change everything.

  • Lesson 3 of 5
  • Free
  • Ages 10+
  • 4 hands-on levels
Try this lesson interactivelyReal Python, running in your browser.

The dragon explains

Numbers, not just words

  1. The dragon: So far you've only given me words in quotes. But I can say numbers too — and those work differently.

  2. The dragon: A number needs no quotes at all. Just put it straight in.

    example.pyPython 3
    print(42)
    Output42
  3. The dragon: And here's the interesting part: without quotes, Python works things OUT before I say them.

    example.pyPython 3
    print(2 + 3)
    Output5
  4. The dragon: I didn't say '2 + 3'. Python did the sum first, then handed me the answer.

    example.pyPython 3
    print(2 + 3)
  5. The dragon: Now watch what quotes do to the exact same thing.

    example.pyPython 3
    print("2 + 3")
    Output2 + 3
  6. The dragon: With quotes it's just symbols to read out. Without them it's a sum to solve. Same characters, completely different meaning.

    example.pyPython 3
    print("2 + 3")print(2 + 3)
    Output2 + 3 5

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 2

    What will I say here?

    question.pyPython 3
    print(10 + 5)
    • 15Correct
    • 10 + 5
    • Nothing — numbers need quotes like words do

    Why: Python does the maths before I speak, so I say 15. The sum happens first, then I say the result.

  2. Question 2 of 2

    And what about this one?

    question.pyPython 3
    print("10 + 5")
    • 10 + 5Correct
    • 15
    • "10 + 5" — with the quote marks

    Why: With quotes it's text, so I read it exactly: 10 + 5. Compare that to print(10 + 5) with no quotes, which gives 15. The quotes are the whole difference.

In the game

What you'll practice

Four levels in the game: one guided first try with the shape of the answer already there, then three to solve on your own.

  1. 1

    GuidedYour first try

    The dragon is counting its hoard and wants to say the number out loud. Numbers do not need quotes — print them exactly as they are.

  2. +3

    PracticeThree more, on your own

Try it yourself — in real Python.

This lesson is part of a free topic: every lesson in it is free, and no card is needed.

Start this lesson for real

Stuck three times? The game offers the answer — unasked.