0

I just stumbled upon this python code:

br: str = "check"

This kind of assignment I have never seen. I get that we make sure that the object br is of class 'str' in this case.

Are there any other benefits using the notation above?

vranjes
  • 47
  • 6
  • for type hints see [PEP 484 -- Type Hints](https://www.python.org/dev/peps/pep-0484/) , [PEP 526 -- Syntax for Variable Annotations](https://www.python.org/dev/peps/pep-0526/) – help-ukraine-now Sep 25 '19 at 14:11

1 Answers1

0

This is an annotation for a variable.

Variable annotations are there to support third-party tooling, such as type checkers; the syntax is new in Python 3.6.

Just as for function annotations, the Python interpreter does not attach any particular meaning to variable annotations and only stores them in the annotations attribute of a class or module

check more at: https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep526

ncica
  • 7,015
  • 1
  • 15
  • 37