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 trialPatrick Perkins
14,619 PointsObject-Oriented Python Frustration Challenge
I am having a bit of trouble getting this bit of code to work. The objective is to override the len() method to work on a list subclass, Liar, Any tips are appreciated
class Liar(list):
def __len__(self):
return super().__len__(self) + 3
1 Answer
Alex Koumparos
Python Development Techdegree Student 36,887 PointsHi Patrick,
So close! You have one small error in this line:
return super().__len__(self) + 3
When you call the __len__
method on the superclass you don't pass self
: self
is the argument that you define on all regular methods in a class but Python supplies self
automatically when you call it.
Hope that helps,
Cheers
Alex
Patrick Perkins
14,619 PointsPatrick Perkins
14,619 PointsOh ok! Thanks!