You've already forked Curso-lenguaje-python
Update Python Ofensivo
This commit is contained in:
26
python-ofensivo/00_ejercicios/05_encapsulamiento09.py
Normal file
26
python-ofensivo/00_ejercicios/05_encapsulamiento09.py
Normal 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)
|
||||
Reference in New Issue
Block a user