Update Python Ofensivo

This commit is contained in:
2023-12-25 21:16:48 +01:00
parent ab95e6f805
commit 490afce41f
8 changed files with 196 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""
Métodos especiales
"""
class Punto:
def __init__(self, x, y):
self.x = x
self.y = y
def __add__(self, otro):
return Punto(self.x + otro.x, self.y + otro.y)
def __str__(self):
return f"Punto({self.x},{self.y})"
p1 = Punto(2, 8)
p2 = Punto(4, 9)
print(p1 + p2) # (6, 17)