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
Jiaying 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,468 PointsHere are items to fix:
- Include the parent class
intin the class definition - do Not include
selfin the__new__method signature - Include generic parameters
*argsand**kwargsin the__new__method signature - Replace the
super()call withint()call - do Not include
selfargument in theint()call - Include
*argsand**kwargsIn theint()` 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,468 PointsChris Freeman
Treehouse Moderator 68,468 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