Python 3, an Illustrated Tour Transcripts
Chapter: Type Annotations
Lecture: An annotation example
0:00 So here's a slightly better example,
0:02 we've got a function called sum2 and it's going to take x and y
0:06 and note here's our colon here and here's our annotation.
0:09 In this case, we have an expression and this is just a string,
0:12 it's the string num and then in this case for y we have another expression there
0:16 and it's an int, and then at the end here we're saying that it returns a float.
0:20 Now this might seem a little weird, we're specifying
0:23 a string and an int and a float as the types here,
0:27 and again, note that Python isn't going to do anything when you run this code,
0:31 but what it does do is it adds a __annotations__ attribute to the function
0:36 and you can look at that attribute
0:39 and it's just a dictionary mapping the parameters
0:42 and then it has a special parameter called return there that gives the return value.