-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetset.py
More file actions
69 lines (60 loc) · 1.5 KB
/
Copy pathgetset.py
File metadata and controls
69 lines (60 loc) · 1.5 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# class car:
# def __init__(self,a=40):
# self.speed = a
# def get_speed(self):
# return self.speed
# def set_speed(self,a):
# self.speed=a
# return
# c1= car()
# print(c1.get_speed())
# c1.set_speed(80)
# print(c1.get_speed())
# c1.speed= 20
# print(c1.get_speed())
#private variable
# class car:
# def __init__(self,a=40):
# self._speed = a
# def get_speed(self):
# return self._speed
# def set_speed(self,a):
# self._speed=a
# return
# c1= car()
# print(c1.get_speed())
# c1.set_speed(80)
# print(c1.get_speed())
# c1.speed= 20 #this will not change the value of variable as it is private now
# print(c1.get_speed())
# class car:
# def __init__(self,a=40):
# self.set_speed(a)
# def get_speed(self):
# return self._speed
# def set_speed(self,a):
# if a<=0 or a>=160:
# print("speed needs to be between 0 to 160")
# else:
# self._speed=a
# return
# c1=car()
# print(c1.get_speed())
# c1.set_speed(0)
# print(c1.get_speed())
class car:
def __init__(self,a=40):
self._speed= a
def get_speed(self):
return self._speed
def set_speed(self,a):
if a<=0 or a>=160:
print("speed needs to be between 0 to 160")
else:
self._speed=a
return
speed= property(get_speed, set_speed)
c1=car()
print(c1.speed)
c1.speed=80
print(c1.speed)