Home > other >  Python magic methods
Python magic methods

Time:12-04

The class Try_int (int) :
Def __add__ (self, other) :
Return the self + other
Def __sub__ (self, other) :
The return of the self - other
This code is wrong, fall into the infinite recursion
But int __add__ method defined, so why not be in infinite recursion??

Correct the following:
The class Newint (int) :
Def __add__ (self, other) :
Return int. __add__ (self, other)
Def __sub__ (self, other) :
Return int. __sub__ (self, other)
  • Related