-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Example16.py
More file actions
50 lines (45 loc) · 1.09 KB
/
Class_Example16.py
File metadata and controls
50 lines (45 loc) · 1.09 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Usage of special dunderscore methods
"""
class Point:
"""
Describing the point with x and y co-ordinates in the graph
"""
def __init__(self, intX, intY):
"""
Initializes the value
:param intX: assigns to x
:param intY: assigns to y
"""
self.x = intX
self.y = intY
def __repr__(self):
"""
representing the point
:return: Point Object
"""
return f"Point({self.x},{self.y})"
def __add__(self, other):
"""
Adds two point object
:param other: Take a Point object as Parameter
:return: Returns the another Point Object
"""
x = self.x+other.x
y = self.y+other.y
return Point(x,y)
def __sub__(self, other):
"""
Subtracts two Point Object
:param other: Takes the Point Object as a Parameter
:return: Returns the another Point Object as a Parameter
"""
x = self.x - other.x
y = self.y - other.y
return Point(x,y)
p=Point(5,10)
q=Point(15,9)
r=p+q
s=p-q
print(r)
print(s)