In Python, specifying type hints for function variables can be done using typing.Callable.
To specify the type hint of a variable as a function, use the following syntax:
from typing import Callable def my_function(func: Callable):
The Callable type can be further refined to specify the types of input and output parameters:
def sum(a: int, b: int) -> int: return a + b
Type Hint:
Callable[[int, int], int]
The general syntax for specifying a function type in a type hint is:
Callable[[ParamType1, ParamType2, ..., ParamTypeN], ReturnType]
The above is the detailed content of How to Specify Function Types with Type Hints in Python?. For more information, please follow other related articles on the PHP Chinese website!