Skip to content

Instantly share code, notes, and snippets.

@JackInTaiwan
Last active October 2, 2018 14:27
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 JackInTaiwan/9504dff4bde49b3a4bb97ee448d1d005 to your computer and use it in GitHub Desktop.
Save JackInTaiwan/9504dff4bde49b3a4bb97ee448d1d005 to your computer and use it in GitHub Desktop.
python_advanced_private_2
class Animal:
def __init__(self, food):
self.blood = True
self.__alive = True
self.__food = food
def __say_something(self):
print("this tutorial is so long...")
def set_food(self, new_food):
self.__food = new_food
def get_food(self):
print(self.__food)
dog = Animal("meat")
print(dog.blood)
# True
print(dog.__food)
# AttributeError: type object 'Animal' has no attribute '__food'
dog.__say_something()
# AttributeError: type object 'Animal' has no attribute '__say_something'
dog.set_food("shit")
dog.get_food()
# shit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment