Explanation:
It's quite straightforward where the issue is. self.area is a variable that is being stored and initialized in the object, not a function. Therefore you can just access it without using () at the end which is used for a function call (or initializing objects of a class, see additional note). Check the code and comments below.
Additional Note: You will see the use of Circle(30) to initialize an object. This convention is used to pass parameters to the __init__ function inside the class while instantiating an object, and it looks the same as if calling a function!
class Circle:
pi = 3.14
def __init__(self, radius=1):
self.radius = radius
self.area = radius * radius * self.pi
def circum(self):
return self.pi * self.radius * 2
my_circle = Circle(30)
#View all the variables initialized in your object
my_circle.__dict__
>>{'radius': 30, 'area': 2826.0}
#Fetch a variable
my_circle.area
>>2826.0
#Call a function
my_circle.circum()
>>188.4
Modification:
Based on what you mention in description this is how you should ideally defined the class you are mentioning -
class Circle:
def __init__(self, radius=1):
self.pi = 3.14
self.radius = radius
def circum(self):
self.circum = self.pi * self.radius * 2
print(self.circum)
def area(self):
self.area = self.radius * self.radius * self.pi
print(self.area)
circle = Circle(30)
#Only radius defined till now
circle.__dict__
#>>{'pi': 3.14, 'radius': 30}
circle.circum()
#>>188.4
circle.area()
#>>2826.0
#After calling the 2 functions, the self dict gets updated with area and circumference
circle.__dict__
#>>{'pi': 3.14, 'radius': 30, 'circum': 188.4, 'area': 2826.0}
Thought process
The way I like to imagine objects of a class is that it is an object is a database with some optional explicit functions defined. The __init__ function initialized the database. You can access everything that the database contains by using the self. Therefore when you pass self to a function, you giving that function access to all of the database that the object is storing. To print everything in that database self you can use my_circle.__self__