specify type of input python code example
Example 1: how to specify an input type to a function in python
def function(input1: int, input2: float, input3: bool, input4: list, input5: str):
pass
Example 2: python type hint list
x: List[int] = [1]
x: Set[int] = {6, 7}
x: int = 1
x: float = 1.0
x: bool = True
x: str = "test"
x: bytes = b"test"
Example 3: python optional type annotation
from custom_module import SomeClass
from typing import Optional
class SubClass:
a_reference: Optional[SomeClass]
def __init__(self):
self.a_reference = None