Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created October 4, 2021 08:20
Show Gist options
  • Save FerdinaKusumah/f05d2cbfbd50201800139a2b48e9b8fc to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/f05d2cbfbd50201800139a2b48e9b8fc to your computer and use it in GitHub Desktop.
class FooBar:
class_attr: str = "foo bar"
def __init__(self, instance_attr: str):
self.instance_attr = instance_attr
if __name__ == "__main__":
foo = FooBar("foo")
bar = FooBar("bar")
# get value from init fooBar class
print(foo.class_attr)
FooBar.class_attr = "foo !!"
# print current class attr value, it will print "foo !!"
print(foo.class_attr)
# check bar class attr value, this will print "foo !!" too
# this is weird ??
print(bar.class_attr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment