-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDunder_Methods.py
More file actions
26 lines (20 loc) · 844 Bytes
/
Copy pathDunder_Methods.py
File metadata and controls
26 lines (20 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
""" _______________________________ """
#!""" Dunder Methods """
class Man():
def __init__(self,name,age):
self.__name=name
self.__age=age
def __add__(self,other): #? Add Function
names = self.__name + " and " + other.__name
ages = self.__age + other.__age
return f"Names combined are {names} and sum of ages is {ages}"
def __lt__(self,other): #? Less Than Function
return self.__age < other.__age
def display(self):
return f"Name is {self.__name} and age is {self.__age}"
man = Man("Akira",20)
man_2 = Man("Amro",30)
print(man+man_2) #* The output is Names combined are Akira and Amro and sum of ages is 50
print(man<man_2) #* The output is True --> age of man(20) < age of man_2(30)
print(man>man_2) #* The output is False --> age of man(20) > age of man_2(30)
""" _______________________________ """