Methods in Python

Lesson 17/20 | Study Time: 10 Min
In Python, everything is an object (be it a list, string etc).

    A method in Python is somewhat similar to function the only difference is that a method is dependent on the object while a function is independent of the object.

      Can you recall we had used a function len() in the earlier modules? Well, this is a function. len() can be used on list, tuple, strings, dictionaries, etc. to get the number of elements in them. While append() is a method that is associated with list only. You cannot use append() method on any of tuple, strings or dictionaries. This append() is associated with list data type only.

        Objects have various methods associated with them (depending on type of the object).

        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.