Functions vs. Methods
Understand the distinct roles of functions and methods in Python programming. Explore how methods are tied to classes and objects, while functions can exist independently, enhancing your coding clarity.
A common misconception and source of confusion is that method and function are used interchangeably or as synonyms which is not at all correct. A method refers to a function that is part of a class and defined inside the body of the class. To access a method, we have to access an instance or object of the class using the ( . ) dot operator.
Method
Python:
PowerShell:
Function
A function does not necessarily have to be defined in a class and can exist as a standalone function.
Methods are functions of the classes. This means that all methods are functions but not all functions are methods.
Powershell: