GENERAL
5 Python patterns every NIA student should know
AWAmina Wanjiru
Nov 14, 2026 · 5:45 AM
Nov 14, 2026 · 5:45 AM
These patterns cover 80% of the Python exercises we do in class.
1. f-strings for output
python
name = "Amina"
score = 87
print(f"{name} scored {score}%")2. Dictionaries instead of long if-else
python
charges = {"ICT": 1500, "Business": 1200, "Electrical": 1800}
print(charges.get("ICT", 0))3. List comprehensions
python
passing = [s for s in scores if s >= 50]
4. range with steps
python
for i in range(2, 22, 2):
print(i) # even numbers5. zip for parallel lists
python
for name, score in zip(names, scores):
print(name, score)
1 comments
FN
Faith Njeri · 15h agoThe dictionary pattern made my assignment so much shorter. Thanks!
Sign in to join the discussion.
About the author
AW
View portfolio
Amina Wanjiru
NIA College student
NIA College student
Write your own
New post