Created
December 14, 2018 01:52
-
-
Save Fhernd/8617f2089a3c426bb55f005341f38b59 to your computer and use it in GitHub Desktop.
Atributos gestionados. Python.
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
class Persona: | |
def __init__(self, nombre): | |
self._nombre = nombre | |
@property | |
def nombre(self): | |
return self._nombre | |
@nombre.setter | |
def nombre(self, nuevo_nombre): | |
if not isinstance(nuevo_nombre, str): | |
raise TypeError('El tipo de dato debe ser string') | |
self._nombre = nuevo_nombre | |
@nombre.deleter | |
def nombre(self): | |
raise AttributeError('Este atributo no se puede borrar') | |
if __name__ == '__main__': | |
edward = Persona('Edward') | |
print(edward.nombre) | |
edward.nombre = 13 | |
del edward.nombre |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment