Intro to Special Methods
Special methods (occasionally called Magic Methods) make your code more elegant and intuitive.
We will go over a couple of special methods in python. In previous lessons, we have learned that any class we create is a type of object. The object superclass allows a user to define a variety of methods in custom classes. Today, we will be going over a few key functions in Python that can be implemented in a class. This will include
__init__, mathematical operators, and comparison operators.
Notice that all special methods are enclosed in underscores, so they will always look like:
Each of these operators allows us to write concise and short code, which allows us to write compact programs without requiring us to make additional helper methods. We will start out with the most fundamental special methods.