class Classname(object),Python中的"object"是什么样的词? [英] class Classname(object), what sort of word is 'object' in Python?

查看:339
本文介绍了class Classname(object),Python中的"object"是什么样的词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个包含其唯一内容的模块时:

When I create a module with its sole content:

class Classname(randomobject):
    pass

然后我尝试运行解释器说未定义randomobject的模块的.py文件.

And I try to run the .py file of the module the interpreter says that randomobject is not defined.

但是当我这样做时:

class Classname(object):
    pass

该模块运行正常.那么,如果object不是关键字,那么它是什么?

The module runs just fine. So if object is not a keyword, then what is it?

推荐答案

object是一个(全局)变量.默认情况下,它绑定到内置类,该内置类是类型层次结构的根.

object is a (global) variable. By default it is bound to a built-in class which is the root of the type hierarchy.

(这带来了有趣的属性,您可以采用任何内置类型,并使用__bases__属性来达到称为对象的类型).

(This leads to the interesting property that you can take any built-in type, and use the __bases__ property to reach the type called object).

不是关键字或运算符的所有内置内容都是标识符.

Everything built-in that isn't a keyword or operator is an identifier.

这篇关于class Classname(object),Python中的"object"是什么样的词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆