Lesson-12 | More Magic Methods | [OOP in Python]

preview_player
Показать описание
This is the lesson number 12 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.

In this lesson we will continue with the concept of Polymorphism and will add few more magic methods. These include magic methods for rich comparison between class objects, for built-in len() function, for making the object iterable and few more.

Link to complete playlist:

Lesson Code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*Review Questions of the Lesson*
1- In __sub__ method can we use (self._groupMember is not other) instead of != ? Why or why not?

2- Where else in the code we can replace == by is (or != by is not)?

#OOP #ObjectOrientedProgramming #Python
Рекомендации по теме
Комментарии
Автор

Nice lecture as usual...keep on uploading more...thank u

Astromoola
Автор

1. Yes, because as the member address are same so we can use them for each other.

arbabkhalid
Автор

Sir, can you give us a favor to extend the date of answering youtube lessons

hafizasadullah
Автор

Sir, i have a question to you and side by side i am showing my arguments also. Sir we have been learning in this course since the start of this course, that "I=" is used to compare the values and "is not" is used where we have same memory location . because it decides that what is an id position of our variable.

sir please guide me how our memory location is same . i have not got this point

hafizasadullah
Автор

1: Absolutely, instead of '!=' we can use 'is not' it because the memory location is same.
2: It can be used in methodslike 'SetGroupMember' and 'DropGroupMember'.

hamidiftikhar
Автор

yes we can replace and it is more convenient when we are comparing group members, variables etc

noornazar
Автор

1: as 'is' method locate the memory where the information is saved, so we can use "Is Not" rather than "!=" since they both have same memory location.

mohammadhozefasaleem
Автор

Q1) We can use 'is not other' as memory address of self._group member and student added in the group are same.
Q2) To check if the student has group member or not, we can use is not 'in the withoutgroupmembers' method.

hishamawan
Автор

1. As it is a special method and we can use (self._groupMember is not other) instead of != because both give same result and both have different memory addresses so where ever the statement is true it gives accurate result.

faqeehakhan
Автор

2- we can use is or is not wherever we compared self with none, such as in withoutgroupmember

ahmadhussain
Автор

1- Yes we can use (self._groupMember is not other) instead of != because self._groupMember and other will b at same memory address if they are groupmember of each other and at different memory addresses if they are not groupmember so (is not) will check whether they are at same memory address or not.

rananomi
Автор

1- Yes, we can use (self._groupMember is not other) instead of using (!=) .Because the memory address of both self and other is the same so we can use "is not".
And as it is first preference so we can use it.

MuhammadBilal-jpye
Автор

1-we use (self._groupMember is not other) instead of != :
because the memory address of both self and other is the same so we can use "is not".
and as it is first preference so we can use it.

ayeshaaslam
Автор

2. We can use is or is not on place of = or != where ever we have any comparison exists. While in this code, we have comparison at setgroupmember and in droppgroupmember. So we have alread done that in sub and add functions.

hamzamushtaqtoor
Автор

1) Yes, we can use (self._groupMember is not other) instead of != because the group members are added in the same memory so when subtracting, we can check the same location. Moreover, it can also save us from any possible errors like len() error.

maheenabdulghani
Автор

1) Yes we can as they have same memory location.
2) can be used in SetGroupMember and DropGroupMember.

zainulhassan
Автор

1_ yes we can use is not as both self and other points to the same memory address.
2_ if there is a comparison between two same objects or between any object and NONE than we can use is or is not expression.

ahmadiftikhar
Автор

1.we can use is not in place of i= because here memory address is same everywhere and is not is used wherever memory address is same
2.is not and is can be used in many methods such as "withoutGroupMember", setGroupMember"and something like that

samrayousaf
Автор

2- We can replace '==' by is and '!=' by is not where ever the comparision is required on the basis of memory address and not on the basis of value or data etc. Like in point class if we want to find out whether two points have same x and y coordinate then we will use '==' and '!=' and if want to find whether both points are in actual same then we will use is or is not. For example we
can use is and is not in setGroupMember, dropGroupMember and withoutGroupMember.

rananomi
Автор

1. Yes we can use (self._groupMember is not other) instead of using "!=" because when we use "is" or "is not" in our code, the interpreter will compare the memory addresses of the datatypes to be compared. As we want memory addresses to be compared in __sub__ method in order to compare if the values are same or not, we can use "is not" in this method.

ibtisamumer
welcome to shbcf.ru