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

I am not able to understand the Task properly!

need help to understand the task

Create a new class named Liar that inherits from list. Override the len method so that it aways returns an incorrect number for the length. Inside of your len method use super() to call list's len method and return a modified version of the length. You won't need any arguments.

For example, if a list has two items in it, the Liar class could return a five. It should never return the correct length.

frustration.py

3 Answers

I understand how you feel. When you get lost like this, try to break down each of the things the instructor is asking and make sure you know the terms and ideas in each sentence.

Create a new class named Liar that inherits from list.

class Liar(list):

Override the len method so that it aways returns an incorrect number for the length. So here you define a magic method with __len__

def __len__(self):

Inside of your len method use super() to call list's len method and return a modified version of the length. You won't need any arguments. For example, if a list has two items in it, the Liar class could return a five. This should be using super(), so the format would be

super().__len__()

It should never return the correct length. Here you have to change it so that always returns something different.

return super().__len__() + 1

Hope this helps. Good luck.

Steven Parker
Steven Parker
210,936 Points

It's a rather odd thing to do, but they want to you override the "len" method to always be wrong (perhaps for a prank?)

They even tell you how to implement it by "use super() to call list's len method" and then modify and return it.

```class Liar(list): def len(self):
super().len() return super().len() + 1