Skip to content

Commit 6a34112

Browse files
authored
Explain accessing class attributes better
1 parent 5374b45 commit 6a34112

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

classes.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ the `Website` class.
171171
>>>
172172
```
173173

174-
In most cases it's not recommended to use class attributes. Using
175-
instance attributes instead is simpler.
174+
`Website.is_online` is `Website`'s class attribute, and in Python you can
175+
access class attributes through instances also, so in this case
176+
`stackoverflow.is_online` points to `Website.is_online`. That can be
177+
confusing, which is why it's not recommended to use class attributes like
178+
this. Use instance attributes instead, e.g. `stackoverflow.is_online = True`.
176179

177180
### Functions and methods
178181

0 commit comments

Comments
 (0)