You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/classes/about.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -185,10 +185,10 @@ class Demo:
185
185
The moment that `<object>.add_two()` is called, and `self.new_var += 2` is read, `new_var` changes from a class variable to an instance variable of the same name.
186
186
187
187
This can be useful during initialization when all instances of a class will need some attribute(s) to start with the same value.
188
-
However, the instance variable then shadows* the class variable, making the class variable inaccessible from the instance where it is shadowed.
188
+
However, the instance variable then [_shadows_](https://oznetnerd.com/2017/07/17/python-shadowing/) the class variable, making the class variable inaccessible from the instance where it is shadowed.
189
189
Given this situation, it may be safer and clearer to set instance attributes from the `__init__()` method as `self.<attribute>`.
190
190
~~~~
191
-
_*[_shadows_][shadowing]
191
+
192
192
193
193
## Methods
194
194
@@ -240,7 +240,7 @@ class MyClass:
240
240
defchange_location(self, amount):
241
241
self.location_x += amount
242
242
self.location_y += amount
243
-
returnself.location_x, self.location_y
243
+
returnself.location_x, self.location_y
244
244
245
245
# Make a new test_object with location (3,7)
246
246
>>> test_object = MyClass((3,7))
@@ -267,7 +267,7 @@ class MyClass:
267
267
defchange_location(self, amount):
268
268
self.location_x += amount
269
269
self.location_y += amount
270
-
returnself.location_x, self.location_y
270
+
returnself.location_x, self.location_y
271
271
272
272
# Alter class variable number for all instances from within an instance.
0 commit comments