Learning outcomes
By the end of this lecture, you should be able to:- use f-strings for clear output
- apply width/alignment/precision specifiers
- print report-style tables cleanly
- solve formatted-output MCQ traps
Why formatted printing matters
- better readability
- predictable alignment in tables
- easier output checking in exams
f-string basics
Width and alignment
- right align:
:>8 - left align:
:<8 - center align:
:^8
Numeric precision
Zero padding
Percentage display
Mini table example
Exam traps
- width controls minimum field size, not max cutoff
:06works for numeric zero-padding- mixing numeric format on string value causes error
Practice
- Print number
73as000073. - Print float
12.34567to 3 decimal places. - Print name centered in width 12.
- Create a 3-column student marks table.
Quick answers
print(f"{73:06}")print(f"{12.34567:.3f}")print(f"{'Riya':^12}")
