Lists
are mutable. ints are immutable
You can add to the list, and this is still the same link to your class. But when you do self.count += 1 , each time you create a new int object, which becomes the scope of this instance. Value never affects the class.
If, for example, you configured it like this:
count = [0] def get(self): self.count[0] += 1
You will see that the score will increase between instances, because you change the member of the list and do not replace the object each time. Not that I recommend this container. Just an example.
You can specifically modify the class directly by doing something like this:
count = 0 def get(self): self.__class__.count += 1
This will replace the int object at the class level every time.
But I would be very careful trying to keep class data between threads like this. It is not thread safe. The problem with read-only data is not really a problem, but changing it from multiple threads can be problematic. It would be much better if you saved your data in a database.
source share