-1

Can I initialize an empty dictionary and typing it at the same time?

For example something like that, however I don't think this is proper.

self.groups: Dict[str, Group]
self.groups = dict()  
Moose1231
  • 9
  • 4

1 Answers1

0

Yes, simply insert the type hint after the variable name in the assignment.

self.groups: Dict[str, Group] = dict()
Barmar
  • 741,623
  • 53
  • 500
  • 612