Pybites Logo Rust Platform

Visibility Rules

Medium +3 pts

🎯 In Python, encapsulation is by convention. You use a leading underscore to signal "private," but anyone can still access it:

class Sensor: def __init__(self, name, value): self.name = name self._value = value # "private" — but not really @property def value(self): return self._value s = Sensor("temp", 72) s._value = -999 # oops — nothing stops this

Python's @property gives you a getter, but there's no enforcement. A determined caller can always reach in and modify _value directly.

Login to see the full exercise.