В чем разница между self.value и просто self при использовании внутри add и radd методов класса. это выдает мне ошибку типа, когда я использую self.value внутри radd , но он просто отлично работает в add методе, как это отличается
class Numstring:
def __init__(self, value):
self.value = str(value)
def __int__(self):
return int(self.value)
def __add__(self, other):
return int(self) + other
# def __add__(self, other):
# return int(self.vaue) + other**
def __radd__(self, other):
return self + other
# def __radd__(self, other):
# return self.vaue + other
foo = Numstring(5)
# working when using both self.value and self
add = foo + 4
#not working when using self.value in __radd__ (but
#working when using only self what is the difference)
add2 = 4 + foo
print(add)
print(add2)