Skip to main content
 首页 » 编程设计

python之Python function 关键字有什么作用

2025年05月04日13pander-it

我在看 this line of code -

    result = function(self, *args, **kwargs) 

而且我找不到 Python 的 function 关键字的定义。有人可以将我链接到文档和/或解释这行代码吗?我直觉地认为我知道,但我不明白为什么我找不到任何关于它的文档。

在搜索http://docs.python.org两者 the new module及其继任者types似乎与它有关。

请您参考如下方法:

那是因为 function 不是 python 关键字。

如果稍微展开 View ,您会看到 function 是一个变量(作为参数传入)。

def autoAddScript(function): 
    """ 
        Returns a decorator function that will automatically add it's result to the element's script container. 
    """ 
    def autoAdd(self, *args, **kwargs): 
        result = function(self, *args, **kwargs) 
        if isinstance(result, ClientSide.Script): 
            self(result) 
            return result 
        else: 
            return ClientSide.Script(ClientSide.var(result)) 
    return autoAdd