Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Regular Instance Methods vs Class Methods vs Static Methods

Give Feedback

In this lesson you’ll dive deeper into the concepts behind instance, class and static methods. The differences are examined using a sample class.

Mariko on Sept. 24, 2020

Thanks for the tutorial! Maybe you covered this, but I’m not sure what you mean by modifying class state in an instance method. Can we somehow access cls in an instance method?

Bartosz Zaczyński RP Team on Sept. 24, 2020

An instance method accepts the self reference, which points to a specific object that shares attributes with the corresponding class. You can use that reference to access object attributes and class attributes, whereas the cls reference only lets you manipulate the class attributes.

It’s worth noting that self and cls are customary names, but you could very well use your own. Ultimately, it’s the decorators or their lack that determine what reference gets passed to a method.

So, to answer your question, you can use the first argument passed to an instance method (conventionally called self) to manipulate an object state as well as the class state.

Become a Member to join the conversation.