Python 3, an Illustrated Tour Transcripts
Chapter: Type Annotations
Lecture: Variable annotations
Login or purchase this course to watch this video and the rest of the course contents.
0:00 So we saw the new style, 526 style of annotating variables. Pep 484 had another style for annotating variables allowed us to do in a comment.
0:12 So if you put the comment with type colon, and then the expression following that, in this case str, we could use this older style pep 484.
0:20 Python 3.6 supports this newer style, and so we can just put the colon and the annotation right after that.
0:26 One thing to note when we create these variable annotations is that there is a global variable called __annotations__
0:33 that will be created and it will be updated with the name and the types in there. Note that, again, this middle variable here does not have a value,
0:41 it's just an annotation for a variable. And so if I try and reference that here, I will get a name error that middle is not defined,
0:48 but note that middle is in my annotation. So when I later assign middle, it should correspond with that type.