加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

函数是python中的第一类对象吗?

发布时间:2020-12-20 13:02:33 所属栏目:Python 来源:网络整理
导读:我正在学习 python的教程.它解释了函数是如何在 Python中的第一类对象. def foo(): passprint(foo.__class__)print(issubclass(foo.__class__,object)) 我得到的上述代码的输出是 type 'function'True 这个程序应该证明函数是python中的第一类对象?我的问题
我正在学习 python的教程.它解释了函数是如何在 Python中的第一类对象.

def foo():
        pass
print(foo.__class__)

print(issubclass(foo.__class__,object))

我得到的上述代码的输出是

<type 'function'>
True

这个程序应该证明函数是python中的第一类对象?我的问题如下.

>上面的代码如何证明函数是拳头类对象?
>第一类对象的属性是什么?
>函数.__ class__表示什么?它返回一个元组< type,function>这意味着什么?

解决方法

以下是Guido在博客中对头等对象所说的内容:

One of my goals for Python was to make it so that all objects were “first class.” By this,I meant that I wanted all objects that could be named in the language (e.g.,integers,strings,functions,classes,modules,methods,etc.) to have equal status. That is,they can be assigned to variables,placed in lists,stored in dictionaries,passed as arguments,and so forth.

whole blog post值得一读.

在您发布的示例中,教程可能会指出第一类对象通常是“对象”类的后代.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读