So from what I understand, in Python class variables are like static variables in C++ and instance variables are like regular member variables. And https://docs.python.org/3/library/typing.html says
class Starship:
stats: ClassVar[dict[str, int]] = {} # class variable
damage: int = 10 # instance variable
so the line with 'damage' shows how to add typing to a variable that is to be used as an instance variable, i.e. each object has its own copy and when a new Starship is made, 'damage' is initialized to 10 for each of them (I think).
But then, why does
class A():
a : {} = {}
l = []
for i in range(2):
a = A()
a.a["a"] = i
l.append(a)
print(l[0].a)
print(l[1].a)
{'a': 1}
{'a': 1}
and not
{'a': 0}
{'a': 1}
as I would expect? I know that I could just initialize the instance variable in __ init __() but I want to add typing to my instance variables. Thanks.