-
-
Save parzibyte/131427c834cff9be91d1a82f8a0ae45f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
https://parzibyte.me/blog | |
""" | |
class Juego: | |
def __init__(self, nombre, precio): | |
self.nombre = nombre | |
self.precio = precio | |
def __eq__(self, otro_juego): | |
# Aquí puedes comparar cualquier cosa de los dos objetos. Debes regresar un Booleano | |
print("Llamada a __eq__!") | |
return otro_juego.nombre == self.nombre and otro_juego.precio == self.precio | |
juego1 = Juego("Cuphead", 180) | |
juego2 = Juego("Cuphead", 180) | |
juego3 = Juego("Resident Evil 2", 430) | |
if juego1 == juego2: | |
print("Son iguales") | |
else: | |
print("NO son iguales") | |
if juego1 != juego3: | |
print("El juego 1 y juego 3 NO son iguales") | |
else: | |
print("El juego 1 y juego 3 SÍ son iguales") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment