Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Advanced Objects Frustration

Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

Dont know why this worked... Overriding __len__

So I just looked at another question and ended up saving the super().len() to a variable and then used the +2 on the variable and it worked... I'm wondering why I had to do that.

frustration.py
class Liar(list):
    def __len__(self):
        super().__len__()
        return __len__() + 2

1 Answer

You're almost there, I think you got the super() confused. Great super function explanation

This is the answer:

class Liar(list):
    def __len__(self):
        return super().__len__() + 2