Now you know how Python class constructors allow you to instantiate classes, so you can create concrete and ready-to-use objects in your code. In Python, class constructors internally trigger the instantiation or construction process, which goes through instance creation and instance initialization. These steps are driven by the .__new__()
and .__init__()
special methods.
By learning about Python’s class constructors, the instantiation process, and the .__new__()
and .__init__()
methods, you can now manage how your custom classes construct new instances.
In this video course, you learned:
- How Python’s instantiation process works internally
- How your own
.__init__()
methods help you customize object initialization - How overriding the
.__new__()
method allows for custom object creation
Now you’re ready to take advantage of this knowledge to fine-tune your class constructors and take full control over instance creation and initialization in your object-oriented programming adventure with Python.
To learn more about the concepts in this course, you can check out:
- Object-Oriented Programming (OOP) in Python 3
- Python’s Documentation on
.__new__()
- Python’s Documentation on
.__init__()
- Python args and kwargs: Demystified
- Supercharge Your Classes With Python super()
- Python’s property(): Add Managed Attributes to Your Classes
- Inheritance and Composition: A Python OOP Guide
- Using Python Optional Arguments When Defining Functions
- Singleton pattern
- Write Pythonic and Clean Code With namedtuple
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
Younes Boukroun on March 18, 2023
The last 2 parts were hard to understand for me, I think giving some real life exemples could help.