Найти - Пользователи
Полная версия: Не работает other
Начало » Python для новичков » Не работает other
1
VOL
class Rmaxplus:
def __init__(self, x):
self.x=x
def __add__(self,other):
return Rmaxplus(max(self.x, other.x))
При сложении двух объектов выдает всегда первый
Что не так??
Python 2.7.9
VOL
Тут я разобрался, надо было дописать
    def __radd__(self,other):
return Rmaxplus(max(self.x, other.x))
def __add__(other, self):
return Rmaxplus(max(self.x, other.x))
def __radd__(other, self):
return Rmaxplus(max(self.x, other.x))
Новая проблема, надо выполнить такое действие: х**2+40*х+20, возникает ошибка из-за двух знаков +
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB