Skip to content

Commit 6c4ff87

Browse files
Update Lecture3.md
1 parent 1e1728d commit 6c4ff87

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tutorials/Lecture3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Encapsulation restricts direct access to some of an object's components (attribu
2020
while True:
2121
print(red_light.led_light_state) # Allowed
2222
red_light.led_light_state = 1 # Allowed
23-
print(red_light.__pin) # Not allowed, raises AttributeError
23+
print(f"Not allowed: {red_light.__pin} ???") # Not allowed, should raise AttributeError
2424
```
2525
> [!Note]
2626
> In Python, identifiers (variable or method names) that start with double underscores (e.g., `__my_var`) are not truly private in the sense of other languages like C# or C++. Instead, Python uses a mechanism called name mangling. When you define a variable with double underscores, Python changes its name internally to `_ClassName__my_var`. This means it is harder (but not impossible) to access it from outside the class.

0 commit comments

Comments
 (0)