This commit is contained in:
adii1823
2021-10-28 17:38:47 +05:30
parent ef37ce0c4e
commit b6eb3ef8a7
32 changed files with 1063 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
# oop/operator.overloading.py
class Weird:
def __init__(self, s):
self._s = s
def __len__(self):
return len(self._s)
def __bool__(self):
return '42' in self._s
weird = Weird('Hello! I am 9 years old!')
print(len(weird)) # 24
print(bool(weird)) # False
weird2 = Weird('Hello! I am 42 years old!')
print(len(weird2)) # 25
print(bool(weird2)) # True
"""
$ python operator.overloading.py
24
False
25
True
"""