Python Class Constructors and Instance Initialization

preview_player
Показать описание
Class constructors are a fundamental part of object-oriented programming in Python. They allow you to create and properly initialize objects of a given class, making those objects ready to use.

This is a portion of the complete course, which you can find here:

The rest of the course covers:
- Fine-tune object creation by overriding .__new__()
- Subclassing immutable Built-in Types
- Returning instances of a different class
- Allowing only a single instance of your class (singleton)
Рекомендации по теме
Комментарии
Автор

is there some sort of playlist for this?

Squash
Автор

I believe there is no initializer list-like where you just need to pass in the constant value to the constructor as parameters..
Let say I have a class "Point" which has x, y, z to be passed in the Point to constructor..it is fine..
But then if I make a class "Triangle"
I want to take three "Points" with it
When defining Triangle object I have difficulty passing in the parameters like in c++ using the initializer list with the '{' '}' and pass in the constant/literal accordingly..but there are no options like this in python..
I need to give the name first to all the points before I can pass it to the triangle constructor..
Is there any way I can do this?
I tried using the *args by python but it seems it can only used for one tuple not more than that..I requested three tuples but it says it cannot do it..
I guess I want to write code back in c++

orangasli
welcome to shbcf.ru