Why does circumference require ()?

Why here need a () when I wrote print(medium_pizza.circumference())?
And since def init return none, why when I test print(medium_pizza.radius), it did return radius value? and why in there I don’t need a () after radius?

class Circle:
  pi = 3.14
  def __init__(self, diameter):
    print("Creating circle with diameter {d}".format(d=diameter))
    # Add assignment for self.radius here:
    self.radius = diameter / 2
  def circumference(self):
    self.circumference= 2 * self.pi * self.radius
    return self.circumference

medium_pizza = Circle(12)
teaching_table = Circle(36)
round_room = Circle(11460)
print(medium_pizza.circumference())
print(teaching_table.circumference())
print(round_room.circumference())
print(medium_pizza.radius())

calling functions and methods require parentheses

init is a magic method, its automatically called when you create a new instance of a class. Within the init method, you can then declare the instance variable(s)

radius is instance variable, accessing variable, instance variable and class variables doesn’t require parentheses.

1 Like