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

Eldin Guzin
Eldin Guzin
6,010 Points

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 38,004 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 38,004 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.