CLASSES
A Class is a blueprint of an object. Classes are a great way for object-oriented programs to group similar data and functions in a manner that is reusable and to avoid redundancy.
Magic Methods
Python Magic Methods are methods specifically to override default python behaviors or rules, most of the time, operator overrides. They can be identified with two prefix and suffix underscores in the method name. Examples of Magic codes are
- the __init__() method in a Class which overrides how python instantiate an object
- the __add__() method which overrides the behaviour of the plus sign. These methods could be the reason we can add two strings with ‘+’ operator with no error and without any explicit typecasting(i.e Converting one data type to another data type)
- The __rep__() method which overrides what gets printed as a variable value
- The __len__() method which probably has to do with the length of a data structure
And etc.
Magic Methods seem to be super cool but super technical and seem to be only applicable in a Class
Inheritance
Inheritance is the technique where a class inherits the properties of another class(which most times is considered as the parent class). And these properties being both attributes and methods. And the main rationale for this is so that the child class can have more varieties without affecting the design of the parent class.


Top comments (0)