Skip to main content
Loading page…
Python Mastery
Chapter 21
Lesson 3 of 4
Common Anti-Patterns (and Fixes)
Contents
Notes
Tutor
Concept
Anti-Pattern 1: Mutable Default Arguments
Loading activity…
Previous
1 / 12
Continue
Contents
Notes
Discussion
Tutor
26 min
12 activities
0 of 12 done
In this lesson
1
Anti-Pattern 1: Mutable Default Arguments
2
Anti-Pattern 2: Bare except
3
Anti-Pattern 3: String Concatenation in Loops
4
Anti-Pattern 4: Manual Index Loops & type() Checks
5
Anti-Pattern 5: God Functions and Premature Optimisation
6
Fix: Mutable Default Argument
7
Fix: String Concatenation in Loop
8
Fix: Manual Index Loop
9
isinstance vs type()==
10
Anti-Pattern or Idiomatic?
11
Pitfall: Mutable Default in Class Attributes
12
Tip: Profile Before Optimising
Objectives
Identify and fix the mutable-default-argument trap
Replace bare except with specific exception handling
Use str.join() instead of string concatenation in loops
Eliminate manual index loops with enumerate/zip
Replace type(x)==T checks with isinstance()
Decompose god functions into focused helpers
Recognise premature optimisation and resist it
Chapter 21 · Pythonic Idioms & Writing Beautiful Code
Core Python Idioms
The Zen, PEP 8 & Naming
Common Anti-Patterns (and Fixes)
Refactoring to Pythonic Code
Previous: The Zen, PEP 8 & Naming
Next: Refactoring to Pythonic Code