Python Tutorials · Python self Parameter

Python self Parameter

Learn all about Python self Parameter in this comprehensive tutorial.

5 min read advanced
  • The self parameter is a reference to the current instance of the class.
  • Without self, Python would not know which object's properties you want to access:
  • It does not have to be named self, you can call it whatever you like, but it has to be the first parameter of any method in the class:
  • You can access any property of the class using self:
  • You can also call other methods within the class using self:

The self Parameter

The self parameter is a reference to the current instance of the class.

It is used to access properties and methods that belong to the class.

python
Note: Note: The self parameter must be the first parameter of any method in the class.

Why Use self?

Without self, Python would not know which object's properties you want to access:

python

self Does Not Have to Be Named "self"

It does not have to be named self, you can call it whatever you like, but it has to be the first parameter of any method in the class:

python
Note: Note: While you can use a different name, it is strongly recommended to use self as it is the convention in Python and makes your code more readable to others.

Accessing Properties with self

You can access any property of the class using self:

python

Calling Methods with self

You can also call other methods within the class using self:

python

Module quiz

2 questions
1

Which of the following is true about Python self Parameter?

2

What is the most common pitfall when working with Python self Parameter?

Answer all questions to submit.