filmov
tv
Lesson-11 | Polymorphism & Magic Methods | [OOP in Python]

Показать описание
This is the lesson number 11 of the lesson series on Object Oriented Programming (OOP) in Python. It will be a complete course with the aim is to cover almost everything needed in Object Oriented Programming.
We will cover an important topic of Polymorphism where one operator has multiple behaviors depending upon the type of the object on which that is being applied. For example, + operator behaves differently when applied on number than when applied on strings.
We will see that we can define the support of different operators for our class objects using different special or magic methods.
Link to complete playlist:
Lesson Code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Review Questions of the Lesson*
1- With the first definition of __add__ method, where the results was list of subjects of both the students, if we execute std1+std2+std3, will it be a list of all three students? Think of it without executing the statement and then verify.
2- With the second definition of __add__ method, where both students become groupMemmber of each other, if we execute std1+std2+std3, it must generate the error as three students cannot be the group members. So are you getting this expected error?
#OOP #ObjectOrientedProgramming #Python
We will cover an important topic of Polymorphism where one operator has multiple behaviors depending upon the type of the object on which that is being applied. For example, + operator behaves differently when applied on number than when applied on strings.
We will see that we can define the support of different operators for our class objects using different special or magic methods.
Link to complete playlist:
Lesson Code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Review Questions of the Lesson*
1- With the first definition of __add__ method, where the results was list of subjects of both the students, if we execute std1+std2+std3, will it be a list of all three students? Think of it without executing the statement and then verify.
2- With the second definition of __add__ method, where both students become groupMemmber of each other, if we execute std1+std2+std3, it must generate the error as three students cannot be the group members. So are you getting this expected error?
#OOP #ObjectOrientedProgramming #Python
Комментарии