Python - How to Create Multiple Class Constructors

preview_player
Показать описание
#Python #Shorts

Python doesn't allow you to overload the constructor in the same way as Java or C# do, where you can just define a constructor with a different number of arguments or different types and you're set. But fortunately, it's not completely impossible. What comes to rescue is @classmethod. It won't feel quite same as an overloaded constructor and will feel more like a static method but it will return a class instance, so it's better than nothing.
-------------------------------------------------------------------------------------
Links:
Рекомендации по теме