Inheritane syntax


I know that the last two lines of this code is not required butt why do I get "" on the console?

    """Makes shapes!"""
    def __init__(self, number_of_sides):
        self.number_of_sides = number_of_sides

# Add your Triangle class below!
class Triangle(Shape):
    def __init__(self, side1, side2, side3):
        self.side1= side1  
my_triangle = Triangle(6,3,7)
print my_triangle


oops , excuse mygrammar ; should read "are not required"




class keyword is missing.

if i run your code here, it prints triangle object as it should


The "class" keyword is in my original code.I appear to be half asleep. I even forgot to type "On the console I get "" " The code is accepted by codecademy.


something is wrong. with my typing. I meant to say that on the console it says


<Triangle object at 0x7fa610917490>


well, print my_triangle will print the object, which means python will tell you the object and its location in memory (<Triangle object at 0x7fa610917490>), how is this different from what you expected?




to make <> show on the forum use format:

but that doesn't answer my question:


I was expecting a print out of the sides of my triangle, i.e 6,3,7 somehow


To make your class do what you expect, you would have to override the repr and return it.

def __repr__(self):
    return repr([self.side1, self.side2, self.side3])

Something like that. Currently it is returning what you are seeing. That is a very simplistic solution to what you was expecting to see. I'd suggest reading up on __repr__ and __str__ if you want to properly understand what it is all doing.


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