Python 3, an Illustrated Tour Transcripts
Chapter: Type Annotations
Lecture: An annotation example
Login or purchase this course to watch this video and the rest of the course contents.
0:00 So here's a slightly better example, we've got a function called sum2 and it's going to take x and y
0:07 and note here's our colon here and here's our annotation. In this case, we have an expression and this is just a string,
0:13 it's the string num and then in this case for y we have another expression there
0:17 and it's an int, and then at the end here we're saying that it returns a float. Now this might seem a little weird, we're specifying
0:24 a string and an int and a float as the types here, and again, note that Python isn't going to do anything when you run this code,
0:32 but what it does do is it adds a __annotations__ attribute to the function and you can look at that attribute
0:40 and it's just a dictionary mapping the parameters and then it has a special parameter called return there that gives the return value.