一、Object與Type
1、摘自Python Documentation 3.5.2的解釋
Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. (In a sense, and in conformance to Von Neumann’s model of a “stored program computer,” code is also represented by objects.)
對象是Python對數據的抽象。Python程序中的所有數據都由對象或對象之間的關系表示。(在某種意義上,並且符合馮·諾依曼的“存儲程序計算機”的模型,代碼也由對象表示的)。
Every object has an identity, a type and a value. An object’s identity never changes once it has been created; you may think of it as the object’s address in memory. The ‘is‘ operator compares the identity of two objects; the id() function returns an integer representing its identity.
每個對象都有一個標識,一個類型和一個值。對象的身份一旦創建就不會改變; 你可以把它看作內存中的對象地址。is運算符比較兩個對象的標識; id()函數返回一個表示其身份的整數。
An object’s type determines the operations that the object supports (e.g., “does it have a length?”) and also defines the possible values for objects of that type. The type() function returns an object’s type (which is an object itself). Like its identity, an object’s type is also unchangeable.
對象的類型決定對象支持的操作(例如,“它有長度嗎?”),並且還定義該類型對象的可能值。type()函數返回一個對象的類型(它是一個對象本身)。與它的身份一樣,對象的類型也是不可改變的。
2、Pyhtml的解釋:
object:
class object The most base type
type:
class type(object) type(object_or_name, bases, dict) type(object) -> the object's type type(name, bases, dict) -> a new type

從上圖可以看出,對象obeject是最基本的類型type,它是一個整體性的對數據的抽象概念。相對於對象object而言,類型type是一個稍微具體的抽象概念,說它具體,是因為它已經有從對象object細化出更具體抽象概念的因子,這就是為什么type(int)、type(float)、type(str)、type(list)、type(tuple)、type(set)等等的類型都是type,這也是為什么instance(type, object)和instance(object, type)都為True的原因,即類型type是作為object、int、float等類型的整體概念而言的。那么,為什么issubclass(type, object)為True,而issubclass(object, type)為Flase呢?從第二張圖,即從繼承關系可以看到,type是object的子類,因此前者為True,后者為False。從Python語言的整體設計來看,是先有對象,后有具體的類型,即對象產生類型,類型從屬於對象,兩者是相互依存的關系。所以:
- object是Python對數據的抽象,它是Python程序對數據的集中體現。
- 每個對象都有一個標識,一個類型和一個值。
- 對象的類型決定對象支持的操作。
- 某些對象的值可以更改。 其值可以改變的對象稱為可變對象;對象的值在創建后不可更改的對象稱為不可變對象。
二、對象層次結構

