Creating the Demo Class
00:00
In this lesson, you are going to create a demo class and inspect its .__dict__
attribute. So to do that, please go to your favorite IDE. I am using VS Code for this recording.
00:15
So create a new file called demo.py
class DemoClass:
You are going to create a class attribute and all this is going to do is say “This is a class attribute”.
00:38
Also create the __init__()
method
00:43
and in there create one instance attribute called instance_attribute
. So self.instance_attribute
, and it will say that “This is an instance attribute”.
01:01
Then create an instance method. So def instance_method(
. It’s an instance method, so that takes self
as an input parameter and you’ll return just a string that says “This is an instance method”.
01:22
Finally, I’d like you to create a class method, so def class_method
and that takes cls
as an input parameter. And all we’ll do is return a string again, that says “This is a class method”.
01:40
Now to make this a class method, you need to use the decorator @classmethod
. So that is your demo class. In the next lesson, you’ll test your code in the REPL.
Become a Member to join the conversation.