Last active
June 4, 2020 06:26
-
-
Save erlnby/11daf5b7c7566c0673ba7e1d5dbc57ed to your computer and use it in GitHub Desktop.
The obvious difference between @staticmethod and @classmethod in Python
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 A: | |
a = 123 | |
@staticmethod | |
def sF(): | |
print(A.a) | |
@classmethod | |
def cF(cls): | |
print(cls.a) | |
class B(A): | |
a = 321 | |
B.sF() #123 | |
B.cF() #321 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment