0

What's this?

def sqr(v:int):
    return v*v

It looks like type restriction, so this function takes just int values, but it doesn't. Is it just a decoration for debuggers?

LazyBum Q
  • 257
  • 4
  • 12
  • This is known as type hinting. You can read more at https://stackoverflow.com/questions/32557920/what-are-type-hints-in-python-3-5 – cozek Dec 31 '20 at 07:11
  • Hi, thanks for the question. If my answer solves your problem, you can mark it as accepted. – Fedor Soldatkin Dec 31 '20 at 07:21
  • Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). "Explain this language feature" is off-topic for Stack Overflow. Stack Overflow is not intended to replace existing tutorials and documentation. – Prune Dec 31 '20 at 07:57

1 Answers1

2

This is the type hinting. It is not a restriction, it's a helper for other developers, most linters as mypy and PyCharm linter also use this to prevent type errors. This feature is optional for using, but it helps you write more clean and testable code.

Fedor Soldatkin
  • 1,133
  • 8
  • 23