Skip to content

Commit decae03

Browse files
authored
Explain methods more
1 parent 7d5378e commit decae03

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

classes.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,14 @@ But is `stackoverflow.info` the same thing as `Website.info`?
237237

238238
It's not.
239239

240-
Instead, `stackoverflow.info` is a **method**. Functions as class
241-
attributes can be accessed as methods from instances. Effbot also
242-
has a `.info` method. So `Website.info(stackoverflow)` does the same
243-
thing as `stackoverflow.info()`, and when `stackoverflow.info()` is
244-
called it automatically gets `stackoverflow` as an argument.
245-
246-
In other words, `Class.method(instance)` does the same thing as
240+
Instead, `stackoverflow.info` is a **method**. If we set a function as a
241+
class attribute, the instances will have a method with the same name.
242+
Methods are "links" to the class attribute functions. So
243+
`Website.info(stackoverflow)` does the same thing as `stackoverflow.info()`,
244+
and when `stackoverflow.info()` is called it automatically gets
245+
`stackoverflow` as an argument.
246+
247+
In other words, `Class.method(instance)` does the same thing as
247248
`instance.method()`. This also works with built-in classes, for
248249
example `'hello'.lower()` is same as `str.lower('hello')`.
249250

0 commit comments

Comments
 (0)