Skip to content

Instantly share code, notes, and snippets.

@etigui
Created October 13, 2020 16:33
Show Gist options
  • Save etigui/c538662f1131d3eaf8de6791e0920766 to your computer and use it in GitHub Desktop.
Save etigui/c538662f1131d3eaf8de6791e0920766 to your computer and use it in GitHub Desktop.
Python class property
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