markdown guide
 

A class method is exactly what the name says: you have a class and the class has a method.

The difference between instance methods and class methods in Python is that the first ones operate on an instance of the class. Class methods operate on the class itself.

The main purpose of methods is to operate on state. Instance methods operate on the state of a single object, class methods operate on the class itself (they don't have access to the object) and they are also available to all objects of that class.

I think you can totally ignore the abc module in Python in the beginning (though I think you can almost always ignore it :)) unless you're interested in building contracts between callers and implementors. They might be useful in big architectures. abc.abstractmethod basically means: "this method here is not a real implementation, I'm just saying to you that you need to override this method and provide an implementation when you use the base class I'm in".

 

Explain an abstract concept of an abstract concept to a 5-year-old? Here's my best try:


You can use the Nintendo Switch game console whether its controllers are attached to its screen or not. When you detach your controllers, you still need to make sure they are controlling the right game console. When the controller is attached, that is like using a regular class constructor. When they are detached, that's like using classmethod. Abstractmethod is like when you lose a button on your controller and have to replace it - you know exactly the type of button you need because of the type of hole you need to fill.

 

Thanks for the explanation, but still confused hahahahaha

 

Also, when does one use ABC?
In Python everyone is used to duck-typing

Classic DEV Post from Apr 24 '17

Compensation tips

Advice on compensation, seeking raises, and determining when to change jobs shared from my own experiences.

Mpho Mphego profile image
Software Engineer in Cape Town, South Africa

Hey there reader...

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❤️