Combining Several Python Variables in One print()

Several boxes at once — sentences, stat sheets, and combined totals.

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

The dragon explains

Boxes and print, together

  1. The dragon: You have used one box at a time so far. Now let us use several together.

  2. The dragon: print() can take many things at once, remember — boxes and words, mixed freely.

    example.pyPython 3
    name = "Ember"age = 200print(name, "is", age, "years old")
    OutputEmber is 200 years old
  3. The dragon: Notice: name and age have NO quotes because they are boxes. The other words DO, because they are just text.

    example.pyPython 3
    print(name, "is", age, "years old")
  4. The dragon: You can also combine two boxes into a brand new number.

    example.pyPython 3
    pile_one = 120pile_two = 35print(pile_one + pile_two)
    Output155
  5. The dragon: Python reads BOTH boxes, adds them together, then says the answer. Neither box changes.

    example.pyPython 3
    print(pile_one + pile_two)

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
    coins = 40gems = 10print(coins + gems)
    • 50Correct
    • coins + gems
    • 4010

    Why: Python reads both boxes, adds 40 and 10, and says the result: 50. Both boxes stay unchanged.

  2. Question 2 of 2

    What will I say here?

    question.pyPython 3
    name = "Ember"print(name, "the dragon")
    • Ember the dragonCorrect
    • name the dragon
    • "Ember" the dragon

    Why: name has no quotes, so I look inside it: Ember. The rest has quotes, so I say those words exactly. Together: Ember the dragon.

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 has a name AND an age now. Say both together, on one line, properly labelled so it reads like a sentence.

  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.