Created
October 13, 2020 16:33
-
-
Save etigui/c538662f1131d3eaf8de6791e0920766 to your computer and use it in GitHub Desktop.
Python class property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class Test: | |
def __init__(self): | |
self.radius = 0 | |
@property | |
def perimeter(self): | |
return self.radius | |
@perimeter.setter | |
def perimeter(self, radius): | |
if not isinstance(radius, int): | |
raise Exception('Check the input') | |
self.radius = 2 * math.pi * radius | |
def main(): | |
test = Test() | |
test.perimeter = 1 | |
print(test.perimeter) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment