Function Annotations
Function Annotations
In Python function annotations helps us to attach metadata to function parameters and return values, add
IDEs and libraries could use annotations to indicate the function’s expected input and return types.
function annotations syntax
We use the following syntax to annotate function parameters and return value. By adding a color (:) after a parameter and an arrow (->) for return types
Annotating functions parameters
In this example:
The parameters a
and b
are annotated with int
, giving us hints that they should be integers
Annotating functions return value
In this example:
-
The parameters
a
andb
are annotated withint
, giving us hints that they should be integers -
The return type is annotated with int