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 Subclassing Built-ins

Juneau Lim
Juneau Lim
13,362 Points

Question about my Liar

question about my Liar When I did below, it didn't work.

class Liar(list):
    def __len__(self):
        truth = super().__len__()
        return truth * 2  # error

However, when I changed the last line to +, it was ok.

        return truth + 2  # OK

What is the difference? I have no idea.

1 Answer

Steven Parker
Steven Parker
231,198 Points

The challenge wants your function to always return an incorrect value (a "lie").

The problem with "truth * 2" is that when the actual value is 0, your function will return the true value.

Juneau Lim
Juneau Lim
13,362 Points

Wow, that's a gotcha. I haven't think about that case. Thanks for the answer!

Juneau Lim
Juneau Lim
13,362 Points

Sorry I thought I did it. :-(