Skip to content

Instantly share code, notes, and snippets.

@moisesnandres
Created February 26, 2015 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moisesnandres/5b372a9a359b6b9f99a6 to your computer and use it in GitHub Desktop.
Save moisesnandres/5b372a9a359b6b9f99a6 to your computer and use it in GitHub Desktop.
Encapsulamiento
>>> class Televisor(object):
... def __init__(self,marca):
... self.__marca = marca
... self.encendido = False
... def encenderT(self):
... if self.encendido == False:
... self.encendido = True
... else:
... print "El televisor ya estaba encendido"
... def apagarT(self):
... if self.encendido == True:
... self.encendido = False
... else:
... print "El televisor ya estaba apagado"
...
>>> tele = Televisor("LG")
>>> print tele.encenderT()
El televisor ya estaba encendido
>>> print tele.__marca()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Televisor' object has no attribute '__marca'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment