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,123 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!