PYTHON:Functions vs Methods

in programming •  6 years ago  (edited)

Today I had a squabble with a classmate of mine over the difference between a method and a function.

Well, he coming from the python side said there was no difference between the two of them while I disagreed with him completely telling him that there was a big difference based on what I knew about python and Java.

Here's a python code instane

class argument:
          def add(a,b):
                C=a+b
                return C
add(9,7)


def add(a,b):
        C= a + b
        return C

add(4,5)

Now considering these two snippets of code above he argued that since they were defined the same way and performed the same function there was no difference.

I totally disagreed with him and here's my own view

Methods
They are associated with an object and can only be implemented within that object. For example if I were to call add wit that last line of code it would give me an error saying add is not defined.
And they can only be called outside their objects with the object coming before the name of the method e.g the right way to call add would be
argument.add()

Functions
For functions they are not associated with any particular object. Therefore they can be called within a class they are not defined and can be called with just their names as seen from the second code snippets.

I also went online and saw a lot of answers to this question with people saying it based on their views. From what I read it seemed a method was a type of function. For me here's my view. What do you think? Don't forget to tell me in your replies.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!