What does the bracket [ ] mean when it comes after a class name?

Yu *_* Gu 5 python python-3.x python-3.6

For example,

class BasicTransitionFunction(TransitionFunction[GrammarBasedState]):
      ...
Run Code Online (Sandbox Code Playgroud)

where TransitionFunction is the base class of BasicTransitionFunction, and GrammarBasedState is also a class name. I only know that [] can be used to indexed arrays. What does it mean here?

Aru*_*ekk 1

这是泛型类型的语法。就像@Sraw所说,这意味着这TransitionFunction是一个泛型类型。例如,List是泛型类型,因此您可以拥有List[Int].

这与 C++ 模板的想法相同(例如std::vector<int>)。

所以这是 a Between sBasicTransitionFunction的子类。TransitionFunctionGrammarBasedState