0

Difference between methods and functions?

I thought I understood but clearly not. What is the difference? My understanding was that a method actually changed the object it was acting on and a fun toon just returned something. I.e. . append () actually changes something where is Len() doesn't. But then I came across the method .count(). Why is this a method? It's not changing anything, just counting the instances of a given something. Probably haven't explained that very well...

28th Feb 2020, 8:46 AM
Andrew Chadwick
Andrew Chadwick - avatar
6 Respuestas
+ 3
I explain it simply : a method is a function that belongs to an object. Learn OOP to understand the difference better.
28th Feb 2020, 8:50 AM
Théophile
Théophile - avatar
+ 2
we have a bit similar discussion here, maybe you can join https://www.sololearn.com/discuss/2184025/?ref=app
28th Feb 2020, 8:53 AM
Taste
Taste - avatar
+ 1
Here, count belongs to an object of type 'list'.
28th Feb 2020, 9:00 AM
Théophile
Théophile - avatar
+ 1
Penny's dropped. Thanks a lot!
28th Feb 2020, 9:01 AM
Andrew Chadwick
Andrew Chadwick - avatar
0
So I've just done a module on OOP. I get what a class is and an object. So in that example, what is the object count belongs to?
28th Feb 2020, 8:58 AM
Andrew Chadwick
Andrew Chadwick - avatar
0
a method
28th Feb 2020, 8:59 AM
Taste
Taste - avatar