We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all" import datetime class Golem: __population = 0 __life_span = 10 def __init__(self, name=None): self.name = name self.built_year = datetime.date.today().year self.__active = True Golem.__population += 1 def say_hi(self): print('Hi!') def cease(self): self.__active = False Golem.__population -= 1 def is_active(self): if datetime.date.today().year - self.built_year >= Golem.__life_span: self.cease return self.__active @property def population(self): return Golem.__population @population.setter def population(self, value): Golem.__population = value g = Golem('Clay') g.population g.population = 100 ga = Golem('New') g.population ga.population help(Golem) Golem.__dict__ g.__dict__ hasattr(Golem, 'population') getattr(Golem, 'population') setattr(Golem, 'population', 10000) g.population # 所以,在很多的情况下,不把数据封装在 Class 内部的话,后面会有很多麻烦。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: