Last active
October 2, 2018 14:27
-
-
Save JackInTaiwan/9504dff4bde49b3a4bb97ee448d1d005 to your computer and use it in GitHub Desktop.
python_advanced_private_2
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 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