Difference between functions and methods

Lesson 18/20 | Study Time: 5 Min
image.png

    You might have a question bugging you: “Why on Earth do we have both functions and methods, when they practically do the same thing?”

      Firstly, let's start with the obvious. There is a clear difference in the syntax:

      A function looks like this: function(something)

      And a method looks like this: something.method()

      Namely: a method always belongs to an object (e.g., in the x.index(2) method, .index() needed the x object to be applicable), while a function doesn’t necessarily depend on a Python object..

      All methods are functions, but not all functions are methods!

      If this makes no sense to you (yet), don’t you worry. I promise, the idea will grow on you as you use Python more and more – especially when you start to define your own functions and methods.

      image.png

      GDPR

      When you visit any of our websites, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and manage your preferences. Please note, that blocking some types of cookies may impact your experience of the site and the services we are able to offer.