Method and Function

Total Post:113

 198  View(s)
Rate this:

What is the difference between method and function in python ?

  1. Post:140

    Re: Method and Function

    Python Method:

    A dependent object is associated by method.It may or may not return any data.A method can operate on the data as a instance variables that is contained by the corresponding class.

    syntax : 

    class class_name 
        def method_name () :
            # method body


    Function is block of code that is also called by its name. The function can have different parameters or may not have any at all. If any data as a parameters are passed ,It may or may not return any data.Function doesn't deal with class and its instance concept. 

    syntax :

    def function_name ( arg1, arg2, ...) :
        # function body

    Difference between method and function :

    function and method both look similar. they perform in almost similar way, but the key difference is the concept of Class and Object.Functions can be called only by its name, But methods can’t be called by its name only, we need class by a reference of that class.