Python Object-Oriented Programming (OOP) (original) (raw)
This Python OOP explains to you the Python object-oriented programming clearly so that you can apply it to develop software more effectively.
By the end of this Python OOP module, you’ll have good knowledge of object-oriented principles. And you’ll know how to use Python syntax to create reliable and robust software applications.
What you’ll learn #
- Create objects in Python by defining classes and methods.
- Extend classes using inheritance.
- SOLID principles in object-oriented programming.
Who this tutorial is for? #
If you’re new to object-oriented programming, or if you have basic Python skills and wish to learn in-depth how and when to correctly apply OOP in Python, this is the tutorial for you.
Section 1. Classes and objects #
- Object-oriented programming – introduce to you the important concepts in Python object-oriented programming.
- Class– learn how to define a class and create new objects from the class.
- Class variables– explain the class variables (or attributes)
- Instance methods – guide you on instance methods and help you understand the differences between a function and a method.
- __init__()– show you how to use the __init__ method to initialize object’s attributes.
- Instance variables – understand the instance variables.
- Private attributes – learn about private attributes and how to use them effectively.
- Class attributes – understand class attributes and more importantly when you should use class attributes.
- Static methods – explain to you static methods and shows you how to use them to group related functions in a class.
Section 2. Special methods #
- __str__ method – show you how to use the __str__ dunder method to return the string representation of an object.
- __repr__ method – learn how to use the __repr__ method and the main difference between __str__ and __repr__ methods.
- __eq__ method – learn how to define the equality logic for comparing objects by values.
- __hash__ method – show you how to make a class hashable using the __has__ method.
- __bool__ method – guide you on how to determine whether a custom object is True or False using the __bool__ method.
- __del__ method – understand how the __del__ method works.
Section 3. Property #
- Property– show you how to use the property class to create a property.
- @property decorator – learn how to use the @property decorator to create a property.
- Read-only property – learn how to define read-only properties and use them for computed properties.
- Delete a property – guide you on how to delete a property from an object.
Section 4. Single inheritance #
- Inheritance – explain to you the inheritance concept and how to define a class that inherits from another class.
- Overriding methods – show you how overriding methods work.
- super() – learn how to delegate to the methods of the parent class from a method in the child class.
- __slots__ – use __slots__ to make the class more memory efficient.
- Abstract class – learn what abstract classes are and how to define abstract classes.
Section 5. Enumeration #
- Enumeration – show you how to define a enumeration in Python.
- Enum Aliases & @enum.unique – introduce to you the enum aliases and how to use the enum.unique decorator to ensure the uniqueness of member values.
- Customize and extend enumerations – learn how to customize the behaviors of enum classes and how to extend the a custom enum class.
- auto – use the enum
auto
class to generate unique values for enumeration’s members.
Section 7. Multiple inheritance #
- Multiple inheritance – learn how to implement multiple inheritance and understand how the method resolution order (MRO) works in Python.
- Mixin – introduce to you the mixin concept and how to implement mixin in Python.
Section 8. Descriptors #
Descriptors – explain how descriptors work and how to use them to make the code reusable.
Data vs non-data descriptors – understand the differences between data and non-data descriptors
__new__ – learn how Python uses the __new__ method to create a new instance of a class.
type class – show you how to dynamically create a class using the type class.
Metaclass – explain the metaclass and show you how to define a custom metaclass to create other classes.
Metaclass example – show you a metaclass example that allows you to inject many functionalities into classes.
dataclass – leverage dataclass to add special methods such as __init__ and __repr__ to custom classes.
Section 10. Exceptions #
- Exceptions – learn about exceptions in the context of objects
- Exception Handling – guide you on how to handle exceptions in the right way using the try statement.
- Raise Exceptions – show you how to use the raise statement to raise exceptions.
- Raise Exception from cause – learn how to modify and forward an existing exception with a cause.
- Custom exceptions – walk you through the steps of creating a custom exception class.
Was this tutorial helpful ?