

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Encapsulation
incomplete
2: Not Security
incomplete
3: Wizard Duel
incomplete
4: Encapsulation in Python
incomplete
5: Wizard Duel
incomplete
6: Encapsulation Practice
incomplete
This lesson's interactive features are locked, please to keep using them
Python is a very dynamic language, which makes it difficult for the interpreter to enforce some of the safeguards that languages like Go do. That's why encapsulation in Python is achieved mostly by convention rather than by force.
Prefixing methods and properties with a double underscore is a strong suggestion to the users of your class that they shouldn't be touching that stuff. If a developer wants to break convention, there are ways to get around the double underscore rule.
class Wall:
def __init__(self, height: int) -> None:
# the double underscore makes this a private property
# but it's not strictly enforced, there are hacks to get around it
self.__height = height
def get_height(self) -> int:
return self.__height