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

Leo Yun Tao
Leo Yun Tao
15,956 Points

TypeError: __len__() missing 1 required positional argument: 'item'

I am trying to do a challenge but when I try to run that code it says TypeError: len() missing 1 required positional argument: 'item', so what does that error mean and how do I fix my code?

class Liar(list):
    def __len__(self, item):
            return self[item]
            return super().__len__(item) + 2 or super().__len__(item) -3

1 Answer

The __len__ method does not need the parameter item. Just remove it, and you should be fine.

Here's my solution:

class Liar(list):
    def __len__(self):
        actual_len = super().__len__()
        return actual_len + 1

Of course, you could just return a random number instead, but that's not the learning objective.

Here's my solution:

class Liar(list):
    def __len__(self):
        return 789