We already have seen many examples of methods while learning objects and data structures types in python. So let’s make our method knowledge more robust.

Methods are functions built into objects. They are always called with an object.

Later on, we will learn how to create our own objects and methods using Object Oriented Programming (OOP) and classes.

Methods perform a specific action on an object and can accept arguments just like a function in python.

General Syntax of a method is:

Here arguments can be self-referring to the object itself.

let’s take some examples of various methods which list has in python.

The methods for a list are:

  • append
  • count
  • extend
  • insert
  • pop
  • remove
  • reverse

Let’s see what they actually do?

Output

Output

Output

Output

After reading this post, you should feel comfortable in calling methods through objects in Python.

Leave a Reply

Close Menu