Introduction to Classes: Instantiate an Object

My query is related to the syntax of the instantiating of an object.

class Triangle(object):
def init(self,angle1,angle2,angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3

number_of_sides = 3
def check_angles(self):
if self.angle1 + self.angle2 + self.angle3 == 180:
return True
return False

my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angles()

The code works but I do not understand why in the last 2 lines of code,


requires no parenthesis whereas


requires paranthesis.
Here is the link for the topic

Thank you.

One is a variable the other a function

Class instance attributes may be values or methods.


is a class variable that is inherited by all instances without having to be set. Every instance will show the same value for that attribute.

>>> my_triangle.number_of_sides

This is an instance method that has access to the angleN variables set on the instance. self is the current owner of the instance, which in the above case is, my_triangle when the method is called on that instance.

>>> my_triangle.check_angles()

We do not need to provide any arguments since the method has, as mentioned, full access to the stored values in the instance variables.