[Tutor] A Question Regarding the Documentation Format

Peter Otten __peter__ at web.de
Sun Sep 24 10:12:37 EDT 2017


Prateek wrote:

> Hi
> 
> Whenever I use help(input) inside Python shell i get the following output:
> 
>>>>
>>>> help(input)
> Help on built-in function input in module builtins:
> 
> input(...)
>     input([prompt]) -> string
> 
> I want to know what the significance of  "-> string". I have tried
> consulting several books but none of them gave me a clear-cut explanation
> for this.

Note that the "->" is also valid Python:

>>> def f(x: int) -> str:
...     return "<{}>".format(x)
... 
>>> f(42)
'<42>'

It was originally "invented" here

https://www.python.org/dev/peps/pep-3107/#return-values

and later morphed into

https://docs.python.org/dev/library/typing.html

According to that f() should take an integer and return a str. This 
information can be used by type checkers like

http://mypy-lang.org/




More information about the Tutor mailing list