17. Instantiate an object - Message on console


#1

Hello there!

My code is

class Triangle(object):
  number_of_sides = 3
  def __init__(self, angle1, angle2, angle3):
    self.angle1 = angle1
    self.angle2 = angle2
    self.angle3 = angle3
  
  def check_angles(self):
    if (self.angle1 + self.angle2 + self.angle3) == 180:
      return True
    else:
      return False
  
my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angles

But I get the following on the console:

3
<bound method Triangle.check_angles of <Triangle object at 0x7f5d719a46d0>>

I reckon I am doing everything fine, but apparently I am not.

Any ideas?

Thanks in advance!


#2

here:

print my_triangle.check_angles

to call the method you need parentheses (function and method calls need it), otherwise you just get a reference to the method


#3

Thanks!

All working fine now! However, I have a question from the next lesson, which I will post on a separate topic. :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.