Python类型系统-对象与类型 [英] Python Type System - Object vs Type
问题描述
我是Python的新手。我熟悉Java,C / C ++和OCaml。我了解Lambda微积分和基本类型理论,因为我在大学修过编程语言课程。
I am new to Python. I am familiar with Java, C/C++, and OCaml. I understand Lambda Calculus and elementary Type Theory because of a Programming Languages course I took at University.
在这种背景下,我尝试阅读以下内容- http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html
Armed with this background, I tried to read this - http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html
在某处,他提到:
- (类型'object')是(类型'type')的实例
- (type' object')是没有对象的子类。
- (类型 type)是它本身的一个实例。
- (type'type')是(type'object')的子类
- (type 'object') is an instance of (type 'type')
- (type 'object') is a subclass of no object.
- (type 'type') is an instance of itself.
- (type'type') is a subclass of (type 'object')
我无法解决这个问题:
- (类型'object')是(类型'type')的实例
- (类型 type)是(类型 object)的子类
这里发生了什么问题?我想听到的是关于这里到底发生了什么的极其深入的原因,以及为什么事情会如此。
What the bleep is happening here? What I want to hear is extremely in depth reasons on what exactly is happening here, and why things are the way they are. No shallow reasons or analogies please.
推荐答案
正在专门讨论对象 type
。对于 type
,所有类型都从< type'type'>
继承。
It is talking specifically about the object type
. For type
, all types inherit from <type 'type'>
.
我相信其他说法只是指出< type'type'>
是对象
;我想到的一个例子是:
I believe the other statement is just pointing out that <type 'type'>
is an object
; an example I thought of from looking further down:
t = list.__class__ # <type 'type'>
t.__bases__ # (<type 'object'>,)
这篇关于Python类型系统-对象与类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!