August 2019
Beginner
482 pages
12h 56m
English
Starting with version 3.6, Python introduced type annotations – these hint at what data types the function expects to get, and what data type it will return.
Let's look at the following example. Here is the negative power function we declared already. This time, however, we added the type annotations both for the function arguments and the outcome:
def negative_power(v:int, p:int)-> int: '''Return negative value v in power p''' return -1 * (v**p)
First of all, those additional characters do not affect code execution in any direct way. Those are type annotations – merely hints at the function's expected data types for arguments and return value, stored within the function – in the same way docstrings are.
While there is no ...