Skip to content

Commit 7810850

Browse files
Merge pull request #226 from AmanShrivastava2710/main
Create Operator_oveloading.py
2 parents a079355 + 8018a27 commit 7810850

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/Operator_oveloading.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Python Program to perform addition
2+
# of two complex numbers using binary
3+
# + operator overloading.
4+
5+
class complex:
6+
def __init__(self, a, b):
7+
self.a = a
8+
self.b = b
9+
10+
# adding two objects
11+
def __add__(self, other):
12+
return self.a + other.a, self.b + other.b
13+
14+
Ob1 = complex(1, 2)
15+
Ob2 = complex(2, 3)
16+
Ob3 = Ob1 + Ob2
17+
print(Ob3)

0 commit comments

Comments
 (0)