Skip to main content
 首页 » 编程设计

python之如何记录参数是python中的函数类型

2024年10月01日8zhenyulu

def method(*, var_param, function_param): 
    """Call 'function_param' with 'var_param' 
 
    :param var_param: the value to pass to the function_param 
    :type log: str 
    :param function_param: the method to call with var_param 
    :type function_param: ????? 
    :return: Nothing 
    :rtype: None 
    """ 
    function_param(var_param) 

我正在使用 pycharm 2017.1.1 进行编码,我想知道我需要在 :type function_param: 中输入什么来指示参数是“函数”?

== 编辑 ==

我尝试使用 function,但 pycharm 提示:

请您参考如下方法:

您可以使用“可调用”类型。

def method(*, var_param, function_param): 
    """Call 'function_param' with 'var_param' 
 
    :param var_param: the value to pass to the function_param 
    :type log: str 
    :param function_param: the method to call with var_param 
    :type function_param: callable[str] 
    :return: Nothing 
    :rtype: None 
    """ 
    function_param(var_param) 

因为你的参数是一个str,你可以在函数签名中设置它。

更多信息: