Private attributes and methods
A private attribute: the double underscore makes Python name-mangle it, so code outside the class cannot reach it directly and gets an AttributeError.
Understanding Private attributes and methods in VCE Software Development U4O1
What it does: Outside the class the name __balance does not exist because Python mangled it, so this line causes an AttributeError. A private attribute starts with a double underscore, like self.__balance. A single name with no underscores is public. Name mangling only changes the attribute's name, for example __name becomes _Student__name. The value is not encrypted.
Common mistakes: A private method is still a method, so its first parameter must be self. It should be def __ok(self, amt):. Without self, calling self.__ok(amt) passes too many arguments and causes an error. This is not a plain assignment, so it does not store the intended value. The private attribute should be created with a simple assignment: self.__age = 0. Otherwise get_age() would return the wrong value.
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 3–79) and word search (Modules 3–114).
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
self.__nameFill in the Blanks
Spot the Error
Student with a class code? Join your class →