Python method vs function

Backtworace
Nov 1, 2020

--

python method vs function vs class
Python method is called on an object, unlike a function. … Since we call a method on an object, it can access the data within it. A method may alter an object’s state, but Python function usually only operates on it, and then prints something or returns a value.

In Python, a method is a function that is available for a given object because of the object’s type. For example, if you create my_list = [1, 2, 3] , the append method can be applied to my_list because it’s a Python list: my_list. append(4) . All lists have an append method simply because they are lists

**A function **is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed. A method is a piece of code that is called by a name that is associated with an object.

--

--

Backtworace
Backtworace

Written by Backtworace

I am founder of <a href=”https://pythonslearning.com”>pythonslearning</a>

No responses yet