-
-
Save KVInventoR/331ead03a8355f93d33de714ebdfab6b 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
Конкретно нужно чтобы были созданы 2 экземпляра класса в которых была бы общая переменная т.е. изменив значение атрибута в одном экземпляре в другом оно бы тоже поменялось...? | |
class Foo: | |
some = 0 | |
@classmethod | |
def setSome(cls, val): | |
cls.some = val | |
@classmethod | |
def getSome(cls): | |
return cls.some | |
f1 = Foo() | |
f2 = Foo() | |
print(f1.getSome(), f2.getSome()) | |
f1.setSome(5) | |
print(f1.getSome(), f2.getSome()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment