Ron TovbinPython Web Development Techdegree Student 6,268 Points
Stuck here. thanks !
Any ideas would be most appreciated 1
class Double(int): def __new__(arg): return super(arg).__new__(arg)
David Capella4,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
So it would look like this:
class Double(int): def __new__(*args, **kwargs): self = int.__new__(*args, **kwargs) return self
Sneha Nagpaul10,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!