Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Add strings

  • concatenation

You guessed right, we now wrap the number in quotes and try to add them together.

Surprisingly it works. Though the result is a bit strange at first. As if Python put one string after the other.

Indeed the + operator is defined when we have two strings on the two sides. It is then called concatenation.

In general you'll have to learn what the mathematical operators do when they are applied to values other than numbers. Usually the operation they do is quite logical. You just need to find the right logic.

a = "19"
b = "23"

c = a + b
print(c)    # 1923

d = b + a
print(d)    # 2319