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 trialJiaying Feng
2,974 Pointsoverride__new__. Not sure how to tackle this question.
Not sure how new works.
class Double:
def __new__(self, int):
super().__init__(self)
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsHere are items to fix:
- Include the parent class
int
in the class definition - do Not include
self
in the__new__
method signature - Include generic parameters
*args
and**kwargs
in the__new__
method signature - Replace the
super()
call withint()
call - do Not include
self
argument in theint()
call - Include
*args
and**
kwargsIn the
int()` call - Remember to return the results of the
int()
call
Post back if you need more help. Good luck!!!
Jiaying Feng
2,974 PointsJiaying Feng
2,974 PointsThank you Chris, I pass the test!!
But I am still a bit confused about the new method though.
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsHere is a good description of
__new_
vs__init__
:Use new when you need to control the creation of a new instance. Use init when you need to control initialization of a new instance.
new is the first step of instance creation. It's called first, and is responsible for returning a new instance of your class. In contrast, init doesn't return anything; it's only responsible for initializing the instance after it's been created.
In general, you shouldn't need to override new unless you're subclassing an immutable type like str, int, unicode or tuple.
From: http://mail.python.org/pipermail/tutor/2008-April/061426.html