-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass2.py
More file actions
40 lines (28 loc) · 705 Bytes
/
class2.py
File metadata and controls
40 lines (28 loc) · 705 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import math
class Point(object):
"""Represents a point in 2-D space."""
def __init__(self, x, y):
self.x = x
self.y = y
def print_point(self):
return print(f"x:{self.x} \ny:{self.y}")
def distance(self):
distance = math.sqrt(self.x**2 + self.y**2)
print(distance)
def __str__(self):
return "object point. point.x is {self.x} and point.y is {self.y}"
##create an object of class Point
a = Point(4,6)
#word2 = Point(5,5)
#word2.print_point()
a.print_point()
a.distance()
print(f'{a}')
##a is a class point,
#I want another point a1 which is equal to a
import copy
a2 = copy.copy(a)
#a2 = a
print (a2 is a)
#a3 = a2
print(a2.x)