Python Text & Strings in Depth
Strings represent text in Python. You can create them with single quotes, double quotes, or triple quotes for multi-line paragraphs. Modern Python features formatted string literals (f-strings), making text building effortless and readable.
"Imagine writing a personalized postcard. Instead of cutting up magazine letters with tape ("Hello " + name + "!"), f-strings let you write a template with fill-in-the-blank placeholders: f"Hello {name}!"."
Deep Dive: How It Works
Strings can use single 'hello' or double "hello" quotes. If your text contains an apostrophe, wrap it in double quotes: "It's a sunny day".
Escape Characters: Use a backslash (\) to escape special characters: \n creates a new line, \t inserts a tab, and \" inserts a literal quote inside double-quoted text.
String Concatenation: You can join strings with the + operator: "Super" + "man" becomes "Superman". You can also repeat strings with *: "Na" * 4 becomes "NaNaNaNa".
Modern f-strings: Prefix the string with an f, like f"Score: {points}". Anything inside the curly braces { } is evaluated as real Python code directly inside the text!
Syntax Blueprint
name = "Dev"
xp = 250
message = f"Welcome {name}, you have {xp} XP!"Put an f before the opening quote and place variables or math inside {curly_braces}.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Forgetting the leading f before the quote: "Hello {name}"Why it happens: Without the leading f, Python treats {name} as literal characters, printing "Hello {name}".
How to fix: Always prefix your formatted strings with f: f"Hello {name}".
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Build a formatted greeting with an f-string
Create a variable called language and set it to "Python".
Use an f-string to print: "I love coding in Python!"
Finished reading and practicing?
Mark this lesson as completed to update your course progress.