Learn Before
Code

Typing Example

from typing import Optional, List, Tuple def function(param1: Optional[int], param2: List[int]): print(param1, param2) >>> function(None, [12, 45, 1]) #None [12, 45, 1] # For this example, param1 had an input of None, while # param2 had a parameter of type List inputted. # The function's output reflects this. >>> function(12, [1, 2]) #12 [1,2] # For this example, param1 had an input of type int, while # param2 had a parameter of type List inputted. # The function's output reflects this.

Type annotations made for each parameter will return a TypeError if the parameter is not of the correct type.

0

1

Updated 2021-08-30

Tags

Python Programming Language

Data Science