0

I am completely confused about the use of annotation in python...

In python documentation it says that Function annotations are completely optional metadata information....you can refer to https://docs.python.org/3/tutorial/controlflow.html

and if it is completely optional then why are we having this in python?

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Amrit
  • 2,115
  • 1
  • 21
  • 41
  • actually the answer for annotations provided on stackoverflow are for java...I want the answer for python...please provide some examples and their respective explanations..... – Amrit Jul 29 '16 at 13:00
  • Out of the three links that I gave you, only one even *mentions* Java. They are all three about Python. – zondo Jul 29 '16 at 19:27

2 Answers2

1

In the PEP 3107 related to these annotations, you can read:

The only way that annotations take on meaning is when they are interpreted by third-party libraries. These annotation consumers can do anything they want with a function's annotations.

You can use it for documentation purposes, linting, validation... But nothing in the standard library use it.

Kmaschta
  • 2,369
  • 1
  • 18
  • 36
0

Functions annotations can be truly great when using a library, it helps you knowing the type of the parameters you need to send without having to crawl into tons of documentation sheets.

Sygmei
  • 467
  • 2
  • 10