Type Hints for Functions
PY · Functionssyntax
def func(param: Type) -> ReturnType:example
from collections.abc import Callable
def apply(
values: list[int],
transform: Callable[[int], int]
) -> list[int]:
return [transform(v) for v in values]
result = apply([1, 2, 3], lambda x: x * 10)
print(result)output
[10, 20, 30]Note Use collections.abc.Callable for function type hints. The format is Callable[[ArgTypes], ReturnType]. For complex signatures, consider typing.Protocol.