一、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程式對資料的集中展現。
- 每個對象都有一個辨別,一個類型和一個值。
- 對象的類型決定對象支援的操作。
- 某些對象的值可以更改。 其值可以改變的對象稱為可變對象;對象的值在建立後不可更改的對象稱為不可變對象。