Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Advanced Objects Frustration

__len__ is not giving me the correct answer

this code seems to be giving me an error please help

class List:

class Liar(List):

    def __init__(self, item):
        self.item = list

    def __len__(self, list):
        return len(list) + 3

1 Answer

Steven Parker
Steven Parker
220,450 Points

You've got the right idea, but a few issues with the implementation:

  • you don't need to define "List"
  • "Liar" will be based on "list" (lower-case)
  • you don't need to override "__init__"
  • the override of "__len__" doesn't need an argument
  • use "super()" to access the "__len__" of the parent class, and it won't need an argument