Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7bbb49d

Browse files
Saidev BattulaSaidev Battula
Saidev Battula
authored and
Saidev Battula
committed
Adding Object Oriented Folder with 01_ClassesAndObject Python file
1 parent 282c0fe commit 7bbb49d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎OOP/01_classAndObject.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Complex:
2+
def __init__(self, a, b):
3+
self.a = a
4+
self.b = b
5+
def print(self):
6+
print(f"{self.a}+i{self.b}")
7+
def add(self, c):
8+
self.a += c.a
9+
self.b += c.b
10+
11+
c1 = Complex(10, 20)
12+
print(c1.a, c1.b)
13+
c1.print()
14+
c2 = Complex(20, 30)
15+
c1.add(c2)
16+
c1.print()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /