Difference between a function and a method in Python









  • What is the difference between a function and a method in Python

    A function is an independent piece of code and must be called independently and is defined outside of a class.
    A method is an independent piece of code which can only be called with reference to the object which contains its definition. A method can operate on data that is contained within the class from which the object is derived.




  • Differences between a method and a function

    In general, methods are functions that belong to a class, functions can be on any other scope of the code so you could state that all methods are functions, but not all functions are methods.


  • python bootcamp 2021
datai analytics