adding all files done so far
This commit is contained in:
26
learning/property/property1.py
Normal file
26
learning/property/property1.py
Normal file
@@ -0,0 +1,26 @@
|
||||
class P:
|
||||
|
||||
def __init__(self, x):
|
||||
print('init')
|
||||
self._x = x
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
print('get')
|
||||
return self._x
|
||||
|
||||
@x.setter
|
||||
def x(self, x):
|
||||
print('set')
|
||||
if x < 0:
|
||||
self._x = 0
|
||||
elif x > 1000:
|
||||
self._x = 1000
|
||||
else:
|
||||
self._x = x
|
||||
|
||||
def double(self):
|
||||
return self.x * 2
|
||||
|
||||
def overwrite(self):
|
||||
self.x = 20
|
||||
Reference in New Issue
Block a user