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 Double

2 Answers

David Capella
David Capella
4,126 Points

I 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
Sneha Nagpaul
10,124 Points

As 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!