Lesson 6 of 16 · 50 min · UG / professional
Strings: quotes, glue and templates
Invoice lines, Windows paths and email subjects are text. Quotes, concatenation and f-strings are the daily tools. Escapes, raw strings and triple quotes are the laptop tools for newlines and file paths.
Class notice message
Strings are text you can shape.
You will be able to
- ✓ Build messages with f-strings
- ✓ Concatenate and know quotes are a house-style choice
- ✓ Know escapes, raw strings and triple quotes exist on a laptop
Workplace text is a string
Invoice numbers, paths and email subjects are text. Single and double quotes are the same type — pick one style and stay. f"Bill {amount} for {vendor}" fills holes from names. + glues two pieces; a template stays readable when there are five.
On a laptop, \n is a newline, r"C:\temp" is a raw string that does not eat backslashes, and triple quotes hold a multi-line usage blurb. This sandbox prints f-strings and concat; copy the extras when you write a CLI help text.
Digits in quotes are still text
"48000" is not an amount until you convert at the edge with int() on trusted digits. Repeating a string with * exists on a laptop ("na" * 3). Here, loop or write the line you need. Adjacent quoted literals glue on a laptop ('Py' 'thon'); variables still need +.
Laptop: raw, triple, repeat
print(r"C:\lab\dht")
print("""Usage:
report.py LABEL
""")
print("go" * 2)
Words that matter
- f-string
- A quoted line with {name} holes.
- Escape
- A backslash sequence like \n — laptop.
- Raw string
- r"..." — backslashes stay literal.
Common mistakes
Avoid: Comparing "RSIL" == "rsil" and calling it a data error.
Do this: Lower both sides, then compare.
Run it step by step
Each box is a real program. Press Run, change a number, Run again — the output must follow your code.
1. Step 1 — fill a template
Change vendor. The sentence follows.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
2. Step 2 — glue a filing line
Concat for a short code + suffix.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Example program — Clean a code, then a sentence
replace is a method you will use again in the next lesson.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Your turn — Subject line
college = "RSIL Demo". Print a line that includes both RSIL Demo and Attendance.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Self-assessment
Check your understanding before you mark the lesson complete.
Progress is stored in a browser cookie on this device.