+ 3

What is the difference between a "function" and a "method"?

18th Sep 2016, 1:50 PM
Daniel de Lizaur
5 odpowiedzi
+ 8
In PYTHON: A function is a callable object and a method is special class of function. --Clear Concept-- Function: A keyword which do any function like input and output. e.g "print" is a function, which shows the output in it's blocks. Method: A keyword which do a procedure on any class, object, arguments like finding maximum and minimum. e.g "len" is method which do a procedure on variable having items and return it's items. i.e len(a)
18th Sep 2016, 2:14 PM
Shahid Islam
Shahid Islam - avatar
+ 3
I'd would add that a function has kind of a global scope in the sense that can be accessed anywhere. But methods are tied to the class where is defined. So, methods have a more limited scope and that is a good thing. Limiting the scope is the core of object programming. You can call a method with the same name on different objects and have its own custom behaviour for each one.
20th Sep 2016, 11:21 AM
Juan Pablo Giuttari
Juan Pablo Giuttari - avatar
0
Good Answer Shahid Islam. Deserve Upvote
20th Sep 2016, 8:10 AM
Salman Tiwana
Salman Tiwana - avatar
0
a function is created by you to execute codes.. a method is a pre-set function that have its own rules and codes and are created for complicated operation
20th Oct 2016, 11:04 AM
basil
basil - avatar
0
Thankyou Salman Tiwana
2nd Feb 2017, 3:40 AM
Shahid Islam
Shahid Islam - avatar