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

Paul Ehizuelen Jr.
Paul Ehizuelen Jr.
4,379 Points

Worked but I'm not 100% sure why. Can someone help me check if i have the right thought process?

I like trying to get have a fundamentally understanding of things, however OOP has begun to elude me especially when making emulating the built-ins.

Biggest questions Do I have to even mention init if want to modify the len functionality of the list class? I looked at other people's sol'n to this challenge the answer appears to be no, but why is that?

Less big questions I don't think I understand the required arguments of init in general (besides self). LIke what exactly do have to include? Why did I have to specify that value was a list variable to pass?

I know super().init() was unnecessary b/c i tried the challenge again without it (hence the #), but I again don't think I know what exactly it does in this context.

I passed this code challenge however I had some superfluous code (b/c i really didn't understand what needs to be there vs. what is optional)

frustration.py
class Liar(list):
    def __init__(self, value = [], *args, **kwargs):
        #super().__init__()
        self.value = value
    def __len__(self):
        return len(self.value) + 3

1 Answer

You don't need to redefine init because you don't need to change the functionality of init. If you don't redefine init, Liar will use the init it inherited from list.

I'm guessing the reason you needed a default value for value is because one of the tests is an empty list created with list(), so an error occured because value wasn't defined.

super().__init__() just initializes the list as if it were empty.

Here's a simpler way to pass the challenge:

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