What is function and method . In python | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 5

What is function and method . In python

in Python :function or method some time I am quit confused with what is function and what is method . I also know about difference between function or method ... how to call function and how to call method . in the Python

23rd Feb 2018, 7:51 PM
suneel singh
suneel singh - avatar
2 Antworten
+ 3
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. In most respects it is identical to a function except for two key differences: A method is implicitly passed the object on which it was called. A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data). Source: https://stackoverflow.com/questions/155609/difference-between-a-method-and-a-function Basically a method is a function in an object and not only able to manipulate globals and passed variables but also object variables
23rd Feb 2018, 8:26 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
Method is how a function is called if it belongs to a class. It is a method from that class.
24th Feb 2018, 3:31 AM
Half Byte
Half Byte - avatar