Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Celsius:
- def __init__(self, temperature = 0):
- self._temperature = temperature
- def to_fahrenheit(self):
- return (self.temperature * 1.8) + 32
- @property
- def temperature(self):
- print("Getting value")
- return self._temperature
- @temperature.setter
- def temperature(self, value):
- if value < -273:
- raise ValueError("Temperature below -273 is not possible")
- print("Setting value")
- self._temperature = value
- Properties provide a way to have both getters and setters with backwards compatibility to just accessing the variable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement