OOP – Private Attributes (underscore convention)
Prefixing an attribute with _ signals it is private and should not be accessed directly from outside the class
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 journey and assign it to your class.
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
Create a free class, add this module to a journey, and track who's stuck.
Create a free teacher account →No credit card. No setup fee. Make a class and invite students in under three minutes.
Practice this topic interactively, track progress, and unlock badges.
Start Learning Free →