Hint: You can adjust the default video playback speed 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.

What Are These Different Method Types Good for in Python?

Give Feedback

Now that you’ve learned about the basic concepts behind instance, class and static methods, the current lesson let’s you run the code you have written to see the actual results of calling the different method types. Furthermore, limits of certain types are revealed.

Comments & Discussion

Zarata on April 20, 2020

At this point I’m wondering about how Python views the terms “self” and “cls” when used as method arguments. These aren’t keywords, and yet they are automatically being interpreted with different understandings: one to symbolize “this” instance, one to symbolize the class. Before I saw this example, I thought “self” could be any group of characters … “Selbst”, “selbt_gleich”, or “soi” or “autobus” for that matter. Are “self” and “cls” true “magic” variables, even moreso than the dunders?

Zarata on April 20, 2020

OH!!! The DECORATORS are more than just pretty things. Aha! Too bad there’s no comment erase! :)

Dan Bader RP Team on April 21, 2020

Are self and cls true “magic” variables, even moreso than the dunders?

You’re on the right track! The position of the self or cls parameter is what’s important, not the name.

Naming the parameter self or cls is just a convention (and one we should stick to for stylistic reasons.)

So you could call the parameter ego, clazz, foobar instead of self and your code would still work, as long as that parameter is in position #1 in the function definition.

More info here: stackoverflow.com/questions/7554738/python-self-no-self-and-cls

Become a Member to join the conversation.