← Recipes📝 String Literals — Four Kinds, One Mission
0 / 500:00
Loading Python in your browser… (first time ~10 MB)
📝
📝 Strings, numbers & decisions Starter · 5 tasks
String Literals — Four Kinds, One Mission
Single, double, raw, and triple-quoted strings each exist for a reason. Know when to use each.
Python has several ways to write a string literal, and each one solves a problem. Single and double quotes are interchangeable, so pick the one that avoids escaping the quotes inside. Escape sequences like \t and \n put invisible characters into a normal string, a raw string (r'...') switches escapes off so backslashes stay literal, and triple quotes let one literal span several lines.
1
Double quotes around an apostrophe
Not run yet
Store the text `It's a beautiful day` in `message` without using a backslash, then print it.
⌘/Ctrl + Enter
🤔 That prints the answer as text. It counts — but the practice is in computing it from the data. Give it a go?
Your output
Run the task to see its output
Expected
2
Escape sequences: tab and newline
Not run yet
Build `table` as ONE string literal that prints two lines: `Name`, a tab, `Age` on the first line and `Ada`, a tab, `36` on the second. Use `\t` and `\n` escapes, then print it.
⌘/Ctrl + Enter
🤔 That prints the answer as text. It counts — but the practice is in computing it from the data. Give it a go?
Your output
Run the task to see its output
Expected
3
Raw strings for Windows paths
Not run yet
Make `path` a raw string so its backslashes print literally: `C:\Users\Alice\report.txt`. Print it.
⌘/Ctrl + Enter
🤔 That prints the answer as text. It counts — but the practice is in computing it from the data. Give it a go?
Your output
Run the task to see its output
Expected
4
Triple quotes for multi-line text
Not run yet
Use a triple-quoted string so `poem` prints exactly three lines: `Roses are red`, `Violets are blue`, `Python is fun`. No `\n` escapes allowed.
⌘/Ctrl + Enter
🤔 That prints the answer as text. It counts — but the practice is in computing it from the data. Give it a go?
Your output
Run the task to see its output
Expected
5
Raw vs normal: count the characters
Not run yet
Set `raw` to the raw string `r"\n"` and `cooked` to the normal string `"\n"`. Print `len(raw)` and `len(cooked)` on one line, separated by a space.
⌘/Ctrl + Enter
🤔 That prints the answer as text. It counts — but the practice is in computing it from the data. Give it a go?