AlgoBazaAlgoBaza
Python for kids ยท Module 1

Lesson 2

Text and numbers in print

After this lesson: You'll tell text from numbers and print several things on one line.

Video

?

The video for this lesson is coming soon.

Explanation

You already know how to print text. Today we'll see what happens when we put a number in print - and whether quotes change anything!

Text or number?

At the school fair Bajtek runs a lemonade stand ๐Ÿ‹, and a computer helps him count. Everything goes great... until the computer does something strange. Watch the story - click Next.

Bajtek's lemonade stand ๐ŸŽฌ

Bajtek
7 for my team and 2 for my sister!๐Ÿง’
๐Ÿฅค๐Ÿฅค๐Ÿฅค๐Ÿฅค๐Ÿฅค๐Ÿฅค๐Ÿฅคthe team+๐Ÿฅค๐Ÿฅคhis sister=โ“
1

The first customers

Kuba comes to the stand. He wants 7 cups of lemonade for his team, and his sister 2 more. How many cups should Bajtek get ready? Let the computer calculate!

Step 1 / 7

Remember:

  • Text - anything in quotes, e.g. "Ala", "7", "2 + 3". Python prints it exactly as it is - character by character.
  • A number - digits without quotes, e.g. 7, 2026, -5. Python can calculate with numbers.

"7" and 7 look the same on the screen, but to the computer they're completely different things - like a sticker with a seven and seven real cups of lemonade.

Two cards: 7 + 3 and "7 + 3" ๐ŸŽฌ

Click Next to go step by step.

?Bajtek
That's the same thing!๐Ÿง’
7 + 3โ‰ "7 + 3"
1

Two almost identical cards

Kuba gives Bajtek two cards: one says 7 + 3, the other "7 + 3". They look almost the same - the only difference is the quotes. But for Python they're two completely different instructions!

Step 1 / 5

7 + 3, two ways

Now step through the program yourself. Line 1 has no quotes - Python calculates and prints 10. Line 2 has quotes - Python copies it character by character and prints 7 + 3.

โ€ฆ
?

Click the arrow and watch: what does Python calculate, and what does it just copy?

Code
1print(7 + 3)
2print("7 + 3")
Screen
โ–
1/3 ยท line 1 runs next

With and without quotes

Step through the program and compare lines 1 and 2.

โ€ฆ
?

Click the arrow and watch: what does Python calculate, and what does it just copy?

Code
1print("2 + 3")
2print(2 + 3)
3print(100)
4print("100")
Screen
โ–
1/5 ยท line 1 runs next

Lines 3 and 4 printed the same: 100. The difference shows up when we start calculating - the number 100 can be added to another number, but the text "100" can't. More about calculating in the next lesson!

The number 2026 and text with 2026

Without quotes 2026 is a number - Python can calculate with it: 2026 + 1 gives 2027. In quotes everything is text, digits too - Python copies it character by character, together with the word Text and the plus.

โ€ฆ
?

Click the arrow and watch: what does Python calculate, and what does it just copy?

Code
1print(2026)
2print("Text 2026")
3print(2026 + 1)
4print("Text 2026 + 1")
Screen
โ–
1/5 ยท line 1 runs next

The robot's calculator ๐Ÿค–

Without quotes the robot calculates, in quotes it only shows the sum.

โ€ฆ
?

Click the arrow and watch: what does Python calculate, and what does it just copy?

Code
1print("100 - 1")
2print(100 - 1)
3print("40 + 2")
4print(40 + 2)
Screen
โ–
1/5 ยท line 1 runs next

Several things in one print

Bajtek has a new friend and wants to introduce himself: the screen should show one line I am 3 years old. But how do you print text and a number on one line? Watch the story - click Next to go step by step. ๐Ÿค–

Bajtek introduces himself ๐ŸŽฌ

Bajtek
๐Ÿง’

Code

๐Ÿช1 year in the shop+๐Ÿก2 years in AlgoBaza=3
Click next to see the goal of this task โžก๏ธ

๐Ÿ–ฅ๏ธ Screen

1

How old is Bajtek?

Bajtek spent 1 year on a shelf in a robot shop, and he has lived in AlgoBaza for 2 years. Together: 1 + 2 = 3 years! Click next to see the goal of this task.

Step 1 / 8

Remember Bajtek's secret: in the brackets of one print you can put several things separated by commas. Text goes in quotes, a number without quotes, and every comma turns into one space - the comma itself doesn't show on the screen.

  • print("I am", 3, "years old") gives I am 3 years old
  • print("Ala", "Ola") gives Ala Ola
  • print(1, 2, 3) gives 1 2 3

Text and a number in one print

Now click the arrow yourself. The first line is Bajtek's introduction. Look at the labels under the pieces: orange ones are text (in quotes), blue ones are numbers (without quotes). The commas join them into one line.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("I am", 3, "years old")
2print("Points:", 100)
3print("Result:", 7 + 3)
Screen
โ–
1/4 ยท line 1 runs next

A comma turns into a space

Click the arrow and watch what happens to the commas between the things in print.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Ala", "Ola")
2print("Bajtek", 3)
3print(1, 2, 3)
Screen
โ–
1/4 ยท line 1 runs next

Commas in print

Every comma becomes a space on the screen.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Bajtek", 3)
2print(1, 2, 3)
3print(2, "+", 3, "=", 2 + 3)
Screen
โ–
1/4 ยท line 1 runs next

A sentence from pieces ๐Ÿงฉ

The first line is one whole piece of text, the second - four pieces with commas. On the screen they look the same: every comma turned into one space.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Ala has 2 cats")
2print("Ala", "has", 2, "cats")
Screen
โ–
1/3 ยท line 1 runs next

A comma inside or outside the text?

A comma inside quotes is part of the text and shows on the screen. A comma outside quotes separates things.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Ala, Ola")
2print("Ala", "Ola")
3print("Ala,", "Ola")
Screen
โ–
1/4 ยท line 1 runs next
?

What will this program print?

print("1 + 1")
print(1 + 1)
?

What does print("I am", 10, "years old") print?

Common mistakes

  • print(Ala) - without quotes Python looks for something called Ala and reports an error.
  • print("5") and print(5) look the same, but only the second can be used in calculations.

Python calculates before it prints

When print has a calculation without quotes, Python first works it out and only then prints the result.

12 + 30
1/2 ยท click the arrow - Python works out the next part

And in quotes?

In quotes it's just text - Python calculates nothing, it copies it character by character.

"12 + 30"
1/2 ยท click the arrow - Python works out the next part

Text next to a result

A comma in print joins text and a number, putting a space between them.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("2 + 3 =", 2 + 3)
2print("I am", 7, "years old")
3print("Result:", 10 + 10)
Screen
โ–
1/4 ยท line 1 runs next

A birthday card ๐ŸŽ‚

A comma puts a space between text and numbers.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Happy birthday,", "Ola!")
2print("Today you turn", 11)
3print("Next year you will be", 11 + 1)
Screen
โ–
1/4 ยท line 1 runs next

A match scoreboard โšฝ

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Poland", 3, ":", 1, "Germany")
2print("Goals in total:", 3 + 1)
Screen
โ–
1/3 ยท line 1 runs next

Bajtek's ID card ๐Ÿชช

Every print has two things: text and a number (or a calculation).

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Name:", "Bajtek")
2print("Age:", 3)
3print("Legs:", 2 + 2)
4print("Eyes:", 2)
Screen
โ–
1/5 ยท line 1 runs next

Counting apples ๐ŸŽ

Python calculates one step at a time, from left to right.

3 + 4 + 5
1/3 ยท click the arrow - Python works out the next part

Shopping at the tuck shop ๐Ÿ›’

The last line works out the total itself - no need to do it in your head.

โ€ฆ
?

Click the arrow - you'll see what print puts between the values.

Code
1print("Lollipop", 2, "zl")
2print("Juice", 3, "zl")
3print("Roll", 1, "zl")
4print("Total:", 2 + 3 + 1, "zl")
Screen
โ–
1/5 ยท line 1 runs next

Remember

  • Text is in quotes ("7"), a number isn't (7).
  • Python calculates with numbers and prints text as it is.
  • A comma in print separates things and becomes a space.

Great! Now the tasks - remember: text in quotes, numbers without.

Tasks from the video

We solve them together in the video - pause it and try first on your own.

Practice tasks

Try to solve them without the video. Stuck? Every task has hints and an editorial.

Sign in to save your progress.