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

Frustration task

Can I get some hints if I am doing this the right way, it gives me a TypeError, that it expects 1 argument but 0 were given.What arguments ? Isn't list the argument that it wants ?? what excatly does len do ? And why do we use super() here, there is no parent class here, so what excatly are we inheriting from? Thanks in advance !

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

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 29,770 Points

Don't forget self and don't need any arguments in the return len

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

Hi Mark, can you explain why we don't need the argument for len? This seems counter intuitive since when len is used "normally" we need to pass the argument through it

Mark Sebeck
Mark Sebeck
Treehouse Moderator 29,770 Points

You have to remember that len() is not the same as _ _ len _ _ ()

len() is a function that you use to find the length of an object. len() takes one argument which is the object you want to find the length of.

_ _ len _ _() is a method that the len() function uses. _ _ len _ _ () is being used behind the scenes by Python. It does't take any parameters. Here it is a method of the list class. You use it like: [list]. _ _ len _ _ ().

Here is a explanation I found on stack overflow.

https://stackoverflow.com/questions/2481421/difference-between-len-and-len

Hope this helps.