🔤 Working with Text, lesson 1 of 5
Strings and joining text
Combine strings with + and *, measure them with len() and convert with str().
8 min
1 exercise
2 quizzes
0/3 solved
Getting Python ready… examples can run in a moment.
A string (str) is a piece of text: letters,
digits, spaces, emoji... anything between quotes.
Strings can be combined:
+concatenates (joins) two strings*repeats a string a number of timeslen()counts the characters
Combining strings
+ doesn't add spaces for you. Put your own name in and count its letters.
What does this print?
You can't + a string and a number: Python won't
guess what you mean and raises a TypeError. Convert
the number to text first with str(), or pass both
to print separated by commas.
Mixing text and numbers
The first two lines work; the third raises a TypeError. Fix it with str(age).
Name badge
Build badge so it reads Hello, my name is Grace!
using the name variable and +.
Need text over several lines? Use triple quotes. Line breaks inside them are kept exactly as typed.
Multi-line strings
An emoji is a single character, so its length is 1.
What does this print?