From 09c205cf156256f5249461d321a7e94354c8262a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Sat, 19 Nov 2022 14:32:04 -0300 Subject: [PATCH] =?UTF-8?q?Exemplo=20de=20uso=20de=20dunder=20methods=20(m?= =?UTF-8?q?=C3=A9todos=20m=C3=A1gicos)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula147.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/aula147.py b/aula147.py index d824e21..cc73b6b 100644 --- a/aula147.py +++ b/aula147.py @@ -24,20 +24,17 @@ class Ponto: def __add__(self, other): novo_x = self.x + other.x novo_y = self.y + other.y - novo_ponto = Ponto(novo_x, novo_y) - return novo_ponto + return Ponto(novo_x, novo_y) def __gt__(self, other): resultado_self = self.x + self.y resultado_other = other.x + other.y - # print(f'{resultado_self=}') - # print(f'{resultado_other=}') return resultado_self > resultado_other if __name__ == '__main__': - p1 = Ponto(4, 2) - p2 = Ponto(6, 4) + p1 = Ponto(4, 2) # 6 + p2 = Ponto(6, 4) # 10 p3 = p1 + p2 print(p3) print('P1 é maior que p2', p1 > p2)