Difference between method and function in python

What’s the key difference between method and function in python?

1 Like

Actually we don’t need to go in depth but you can understande that the main difference is only that a function works on it’s own (I know it sounds cocky) and a method requires an object to work on for eg,
let’s define a function to add two numbers…
image

Now this function return the addition of two numbers, nothing else…
Moreover it works independtly of the other program…
So, if we did add_two(9, 10) we would simply get 19.

Now a method works on object
So, what does it mean…It just means that the set of instructuions i.e. method is defined to be used on object (in-built or custom)
For eg,
count method works on a list and takes a parameter i.e. the value you want to count >>
image

So, there is not a major difference but it’s important to know that a method cannot be used independently >>

As you can see there’s an error…

Hope this helps…
It’s not the greatest explaination so I’ll attach a link to a post…if you want to go in more depth…
image
I found this On STACKOVERFLOW…

Thank you very much for your valuable comments

1 Like