- In Python, type annotations are only syntactic sugar and do not affect the runtime behavior of the code.
- The grammar of Python allows for type annotations to be expressions, even if they do not make sense as a type.
Therefore, when you assign a value to a variable using the : instead of = operator, Python interprets it as a type annotation and ignores the expression after the colon.
This behavior can lead to errors or unexpected results, especially if you are using a linter that checks for type correctness.
It is always best to use the = operator to assign values to variables and to use type annotations only when they provide meaningful information about the expected type of the variable.