Skip to content

Instantly share code, notes, and snippets.

@Zagrebelin
Created March 2, 2017 11:57
Show Gist options
  • Save Zagrebelin/6f69fe4ed7b3c2df0a9f9a52d7510297 to your computer and use it in GitHub Desktop.
Save Zagrebelin/6f69fe4ed7b3c2df0a9f9a52d7510297 to your computer and use it in GitHub Desktop.
classmethod.py
class Foo:
x = 2
@classmethod
def multy_cls(cls, y):
return cls.x * y
def multy(self, y):
return self.x * y
f1 = Foo()
f2 = Foo()
f1.x = 10
f2.x = 20
print(Foo.x, f1.x, f2.x) # output: 2 10 20
print(Foo.multy_cls(3)) # output: 6
print(f1.multy_cls(4), f1.multy(4)) # output: 8 40
print(f2.multy_cls(5), f1.multy(5)) # output: 10 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment