Python — Basic Review before diving deeper 05
Want to recall the memory of Python easily?
This is the note taken while I learned Python “again”, hope it helps you too.
There are additional links in the article for you to understand further information.
Quick tip |
Find ⚡for each topic
☘️Directory
- OOP(Object-Oriented Programming)
- Exercise 08 — The most expensive price
- Classmethod vs. Staticmethod
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism
- Exercise 09 — Cat Inheritance
- Super
❤️Good Resources
Bro code | Python full course
ZeroToMastery | Pyhton
Codes in Github
⚡OOP
Complete Explanation | GeeksforGeeks
🔸Encapsulation, Abstraction, Inheritance, Polymorphism are four pillars in Object-Oriented Programming
What you should know,
🔹class — a collection of objects
🔹__init__ is similar to constructors in C++ & Java, always executed when the class is being initiated
🔹self — represents the instance of the class — More in GeeksforGeeks
The result shows info of the object person. And 0x7f6f682371f0 is where the object located in the memory.
Add a method in class.
More attributes are available too.
❗Class Object attributecan be called by object name or self.
Method in Class, it looks like this.
Can you replace object name — person with self?
The most expensive Price
Exercise 08
⚡classmethod & staticmethod decorator
Which is the method can be called on the class without instantiating it into an object.
🔹A class method can access or modify the class state while a static method can’t access or modify it.
Get Yen Wang’s stories in your inbox
Join Medium for free to get updates from this writer.
🔹Generally use static methods to create utility functions.— GeeksforGeeks
🔸classmethod
🔸Staicmethod
⚡Encapsulation
It encapsulates all the data(functions, variables…) into a big object.
⚡Abstraction
An abstract class can be considered as a blueprint for other classes.
A class which contains one or more abstract methods is called an abstract class. An abstract method is a method that has a declaration but does not have an implementation.— GeeksforGeeks
⚡Inheritance
More in W3Schools
🔹Allow a class that inherits all the methods and properties from another class.
🔹Parent class also called base class(The inherited class)
🔹Child class also called derived class(The class inherited from parent class)
Less development and maintenance expenses result from an inheritance — GeeksforGeeks
This is not right.
⚡Polymorphism
🔹Means “many forms”
🔹With polymorphism, we can execute same method for other classes
Actually there is a Drier way to serve the walk method. As you see, I use walk() method three times which are not really DRY(Don’t repeat yourself).
Have a look at the Exercise 09 — Cat Inheritance.
⚡Cat Inheritance
Exercise 09
😮⚡⚡Do you see the beauty of this?
⚡Super
More in GeeksforGeeks
🔹Inherit all the methods and properties from another class
How Inheritance works without super()?
We encounter the error that both class has __init__ constructor trying to call name_ & name, but a class didn’t have name attribute.
A simplier way
to understand the structure for this kind of situation.
Now, we can go back to the correct version.








