Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyPropertyDecorator
#Python 2.7.17 #PyPropertyDecorator #this code is created by Rezaul Hoque on January 04,2022;contact: jewelmrh@yahoo.com,Dhaka, Bangladesh #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; class Fruit: def __init__(self, fruit, price,qty): self.fruit = fruit self.price = price self.qty=qty @property def price(self): return self.price # price=property(fget=get_price,fset=set_price) @property def qty(self): return self.qty # qty=property(fget=get_qty,fset=set_qty) @price.setter def set_price(self, price): if price <= 0: raise ValueError('Price must be positive') self.price = price @qty.setter def set_qty(self,qty): if qty<= 0: raise ValueError('Quantity must be positive') self.qty = qty a = Fruit('Guava',10,1) print(a.fruit) print(a.price) print(a.qty)
run
|
edit
|
history
|
help
0
Simple code to find all divisors for a number
bacs_class
Printing
Gani
working with strings
Aisha Wall
on_off_3
Aufgabe 16
single_digit
dice_02_while