juniorPython

Class 'self' keyword

Updated May 4, 2026

Short answer

Points to the current instance of the class.

Deep explanation

It allows methods to access and modify the attributes of the specific object being called.

Real-world example

Distinguishing between different 'Car' objects (one red, one blue).

Common mistakes

  • Leaving 'self' out of method definitions or '__init__'.

Follow-up questions

  • Is 'self' mandatory?

More Python interview questions

View all →