1. Concept library
  2. Python Foundations
  3. Module 6: Strings and formatting

Concept

f-strings

An f-string puts expressions straight into text: f"{name} owes {amount:.2f}". Format specs after the colon control decimals, padding and alignment.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain how braces in an f-string drop into Python
  2. Write an f-string with a format spec for decimals, padding and alignment
  3. Spot the missing f prefix that prints the braces literally

In practice

A few lines that show f-strings doing its job.

Python
name = "Ada"
amount = 1234.5

print(f"{name} owes {amount:.2f}")      # Ada owes 1234.50
print(f"{amount:,.0f}")                  # 1,234
print(f"{name:>10}|")                    #        Ada|
print(f"{len(name) * 2 = }")             # len(name) * 2 = 6

The common mistake

Watch for

Forgetting the f prefix. "Hello {name}" is printed literally, braces and all, with no error to tell you.

What to know first

Your roadmap puts these before f-strings, unless you already know them.

How it stays learned

Once a session shows you understand f-strings, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← String methods
Next in the moduleSplitting and joining →