Lesson 4.7
An f-string puts values right inside the text, and after a colon you can set the width and the side to align to:
| Form | What it does |
|---|---|
f"Hello, {name}" |
inserts the value |
f"{name:>10}" |
width 10, right-aligned |
f"{name:<10}" |
width 10, left-aligned |
f"{name:^10}" |
width 10, centred |
The letter f before the quotes is required: without it the curly braces stay as text.
The name name, the number score and the width width are set by the check. Print,
in order:
Name: <name> — with a label;width, between two |;width, between two |.Alignment is set in the f-string after the colon: <, >, ^.
{name:>10} pads on the left, {age:<5} pads on the right, ^ centres.
The width is the total number of characters, including the value itself.