0と1を次々返す方法
これってもう出た?
class Toggle(object): @property def value(self): ret = self._f self._f = not self._f return ret def __init__(self): self._f = True toggle = Toggle() print toggle.value print toggle.value print toggle.value print toggle.value
これってもう出た?
class Toggle(object): @property def value(self): ret = self._f self._f = not self._f return ret def __init__(self): self._f = True toggle = Toggle() print toggle.value print toggle.value print toggle.value print toggle.value