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 trialRon Tovbin
Python Web Development Techdegree Student 6,268 PointsStuck here. thanks !
Any ideas would be most appreciated 1
class Double(int):
def __new__(arg):
return super(arg).__new__(arg)
2 Answers
David Capella
4,126 PointsI do not believe you want to use super because you want to create a new instance as int.
In the question, "whatever is passed in as arguments and keyword arguments." means *args
for arguments and **kwargs
for keyword arguments so def __new__(*args, **kwargs)
To create a new instance you have to set a variable. ( It does not have to be a variable named self).
Then, you set int as a new int instance such as self = int.__new__(*args, **kwargs)
and finally you have to return self
So it would look like this:
class Double(int):
def __new__(*args, **kwargs):
self = int.__new__(*args, **kwargs)
return self
Sneha Nagpaul
10,124 PointsAs far as I've understood this, the whole idea behind new is to be able to create immutable objects.
Hence, the super class will be referenced using int instead of super().
Arguments get passed once to the function chained to the superclass reference. And, you want *args and **kwargs in there too.
Hope this helps!