简体   繁体   English

function 是 python 中内置 class '函数'的实例吗?

[英]is a function an instance of built-in class 'function' in python?

In python, when we create a function, the class or type of that function is function : In python, when we create a function, the class or type of that function is function :

 def temp():
    pass

>>> type(temp)
<class 'function'>
>>> temp.__class__
<class 'function'>

I wonder if the code def ~(): calls the __call__ function of the built-in class function .我想知道代码def ~():是否调用了内置 class function 的__call__ function I want to check the source code of the built-in class function , but I don't know where it is.我想查看内置 class function的源代码,但我不知道它在哪里。

If you know, please answer.如果你知道,请回答。

From the link given by @IainShelvington in the comments: https://github.com/python/cpython/blob/master/Objects/funcobject.c来自@IainShelvington 在评论中给出的链接: https://github.com/python/cpython/blob/master/Objects/funcobject.c

There is no __call__ call or reference anywhere in the source code.源代码中的任何地方都没有__call__调用或引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM