Python Programming - Objects - Discussion

Discussion Forum : Objects - General Questions (Q.No. 6)
6.
Consider the following Python code:
class Circle:
    def __init__(self, radius):
        self.radius = radius

    def calculate_area(self):
        return 3.14 * self.radius * self.radius
How would you create an instance of the Circle class with a radius of 5?
circle_instance = Circle.create(5)
circle_instance = Circle(radius=5)
circle_instance = new Circle(5)
circle_instance = Circle(5)
Answer: Option
Explanation:
The correct way to create an instance of the Circle class with a radius of 5 is to use the constructor and pass the value as a named argument.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.