All lessons

Working with Text

7 min · Python

Join text together, measure it, and change its case.

Python · Working with Text0/5 cleared

Enemy 1 of 5

Text values are called strings — a string is simply a sequence of characters wrapped in quotes, whether that's a single letter, a word, or a whole paragraph. You've already been using them for every print call so far; now it's time to actually work with them.

You can join two strings with a plus sign, an operation called concatenation. It's the same + you use for arithmetic, but Python is smart enough to know that adding two strings means gluing them together character-for-character rather than doing math — as long as both sides of the + are strings. Mixing a string and a number with + (like "Score: " + 10) will actually raise an error, because Python won't silently guess whether you meant to convert the number to text.

Run this to glue a greeting and a name into one line.

You
Packet Wolf

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, Ada