Geek Culture
Published in

Geek Culture

Python — Type Annotation for Functions and Class

Python type annotation deep dive

Annotate Parameters and Return Value

To annotate the type for a function, you need to type annotate each formal parameter, and at the same time annotate the return value of the function. For example:

def add(x: int, y: int) -> int:
return x + y

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store