Skip to content

Instantly share code, notes, and snippets.

@att288
Last active December 22, 2020 11:13
Show Gist options
  • Save att288/92e6f7bc1e8dc99abc9c8ce7ac3a3d38 to your computer and use it in GitHub Desktop.
Save att288/92e6f7bc1e8dc99abc9c8ce7ac3a3d38 to your computer and use it in GitHub Desktop.
class Example:
class_attr_1: str = 'attr_1'
@classmethod
def foo(cls, message: str) -> None:
print(f"Message sent from foo: {message}")
# access class attribute
print(cls.class_attr_1)
# call static method bar from a class method
cls.bar('(from foo) BAR')
@staticmethod
def bar(message: str) -> None:
print(f"Message sent from bar: {message}")
if __name__ == "__main__":
Example.foo("FOO")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment