OOP – Private Attributes (underscore convention)
Prefixing an attribute with _ signals it is private and should not be accessed directly from outside the class
Understanding OOP – Private Attributes (underscore convention) in Python
What it does: A single underscore is a convention meaning 'do not access directly'. Getters provide controlled read access to private attributes. _name signals 'treat this as private' — Python won't stop you accessing it though. __name becomes _ClassName__name — Python mangles it to make accidental access harder. A setter can check that a new value is valid before storing it. A getter method reads a private attribute safely without exposing it directly. Hiding attributes forces callers to use your methods, where you can validate changes. Python allows it technically — the underscore is just a warning not to do it.
Common mistakes: Directly setting _balance bypasses validation. Use deposit() method. __balance is name-mangled. Access through a getter method.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 51–63) and word search (Modules 41–63).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
_variableFill in the Blanks
Spot the Error
Student with a class code? Join your class →