Last active
December 20, 2015 22:29
-
-
Save eungju/6205176 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ➜ ~ python self_and_cls.py | |
| 1 0 | |
| 1 1 |
This file contains hidden or 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 Hello(object): | |
| variable = 0 | |
| def __init__(self): | |
| self.variable = 0 | |
| @classmethod | |
| def increase_class_variable(cls): | |
| cls.variable += 1 | |
| def increase_instance_variable(self): | |
| self.variable += 1 | |
| o = Hello() | |
| Hello.increase_class_variable() | |
| print Hello.variable, o.variable | |
| o.increase_instance_variable() | |
| print Hello.variable, o.variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment