Is it possible to type hint a lambda function?

后端 未结 3 1139
不思量自难忘°
不思量自难忘° 2020-12-14 05:03

Currently, in Python, a function\'s parameters and return types can be type hinted as follows:

def func(var1: str, var2: str) -> int:
    return var1.inde         


        
3条回答
  •  我在风中等你
    2020-12-14 05:59

    Since Python 3.6, you can (see PEP 526):

    from typing import Callable
    is_even: Callable[[int], bool] = lambda x: (x % 2 == 0)
    

提交回复
热议问题