This Python program defines a class named Circle that receives the radius as an input and stores it in a variable named r.
This structure is useful for geometric calculations such as area and circumference.
# Define the Circle class
class Circle:
def __init__(self, radius):
self.r = radius # Store radius in variable r
# Create an instance of the class with a specific radius
c = Circle(5)
# Display the radius
print("Circle radius:", c.r)
Circle radius: 5
- The Circle class is defined with an __init__ constructor
- The radius is passed as an argument during object creation
- The radius is stored in self.r for future use
- The value of r is printed using print()