Python Object-Oriented Python Advanced Objects Double

bright chibuike
bright chibuike
3,245 Points

subclassing built-ins

please what could the solution to this question

Now override new. Create a new int instance from whatever is passed in as arguments and keyword arguments. Return that instance.

You should remove the pass.
class Double(int):
   def __new__(*args,**kwargs):

How did you solve the first one? I can you help me?

2 Answers

Steven Parker
Steven Parker
207,988 Points

You've removed the "pass", but you still need to do the other parts of the instructions:

  • Create a new int instance ...
  • and then ... Return that instance.
Miranda Chen
Miranda Chen
6,945 Points

First create the int instance

self = int.__new__(*args, *kwargs)

Then return the instance

return self

this isn't quite right either