February 2009
Intermediate to advanced
68 pages
1h 51m
English
Functions and methods can be defined with annotations—expressions that can be used in a function’s signature. Here’s the general syntax:
def functionName(par1 : exp1, par2 : exp2, ..., parN : expN)-> rexp: suite
Every colon expression part (: expX) is an optional annotation, and so is the arrow return expression part (-> rexp). The last (or only) positional parameter (if present) can be of the form *args, with or without an annotation; similarly, the last (or only) keyword parameter (if present) can be of the form **kwargs, again with or without an annotation.
If annotations are present they are added to the function’s __annotations__ dictionary; if they are not present this dictionary is empty. The ...