0% found this document useful (0 votes)
3 views2 pages

Understanding Python Circle Class

The document outlines the structure and functionality of a Circle class in Python. It includes details about class attributes, instance methods, static methods, class methods, and property decorators for managing the radius. Key features include a custom initializer, methods for creating a unit circle, setting the origin, doubling the radius, and accessing the radius property.

Uploaded by

Vivek Reddyvari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Understanding Python Circle Class

The document outlines the structure and functionality of a Circle class in Python. It includes details about class attributes, instance methods, static methods, class methods, and property decorators for managing the radius. Key features include a custom initializer, methods for creating a unit circle, setting the origin, doubling the radius, and accessing the radius property.

Uploaded by

Vivek Reddyvari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

©2019 MathByte Academy

Recap
c = Circle() à c in an instance of Circle
class Circle:
origin = (0, 0) class attribute – [Link]
def __init__(self, r): custom initializer à instance method (bound to instance)
self._r = r
_r is an instance attribute (private by convention only)
@staticmethod à can still access using c._r
def create_unit_circle():
return Circle(1) static method – not bound to anything
c2 = Circle.create_unit_circle()
@classmethod
def set_origin(cls, x, y): class method – bound to class
[Link] = (x, y)
Circle.set_origin(10, 10)
à can also be called using c.set_origin(10, 10)
def double_radius(self):
self._r *= 2 instance method – bound to instance
c.double_radius()
@property
def radius(self):
return self._r
instance property (radius) with getter/setter methods
@[Link]
def radius(self, value):
self._r = value
©2019 MathByte Academy

You might also like