3

I'm learning Python. Have knowledge in other languages. There's a difference between methods and functions in python which confuses me. There's a very minute difference. Is my above conclusion on functions and methods true? In what better way can they be differentiated.

  • answered here http://stackoverflow.com/questions/155609/difference-between-a-method-and-a-function and here http://stackoverflow.com/questions/20981789/difference-between-methods-and-functions python is irrelevant – Padraic Cunningham Dec 24 '15 at 13:29

3 Answers3

2

Most of the answer is here : https://wiki.python.org/moin/FromFunctionToMethod

To make a long story short: a method is the partial application of a function to an object.

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
1

Both are logically types of functions, but method or member function specifically refers to the subset of functions that are defined on classes and that operate on specific instances of the class.

In Python, specifically, it may also refer to functions where the self parameter has already been bound to a specific object (as opposed to the free-standing form where self isn't bound).

Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200
1

Yes, in Python functions and methods are different but similar. Methods needs to take the 'self'(the reference on the caller object) keyword like first parameter,instead functions needs 0 or more parameters.

Drakenden
  • 38
  • 1
  • 11
  • `self` is not a keyword, and Python's "methods" are what you get at runtime when an attribute lookup resolves to a function belonging to the class (or class parents) `__dict__`. What you define with a class (and that gets called by the method) is still a plain function. – bruno desthuilliers Dec 24 '15 at 14:02
  • your're right,self is a sort of coding convention like Python'cls or Java's 'this' (sorry but my english lexicon is poor :P) – Drakenden Dec 24 '15 at 14:16
  • 1
    In Java `this` is a keyword and is not part of the method signature. OTHO Java doesn't have functions, only methods. – bruno desthuilliers Dec 25 '15 at 10:53