python类属性描述_如何描述Python对象,以及属性、标识、类型和值之间的关系?...
雖然可以通過屬性訪問對象的類型,但它的類型不僅僅是一個屬性——該類型定義了對象在擁有任何屬性之前是如何創建的。僅憑這個事實,這些語句都不足以描述Python對象。
我這么說:In Python, everything is an object.
An object is a block of information, which has a type, which defines its creation and how it interacts with other objects, an identity, which differentiates it from all other objects, and a value, which is the information in the block. Attributes are other objects associated with a given object, including the object that is its type.
然后,您應該給出一些人們可能不希望成為對象的例子,比如函數。
關于“什么是對象”的段落可以在Dive Into Python中找到:Everything in Python is an object, and almost everything has attributes and methods. All functions have a built-in attribute __doc__, which returns the doc string defined in the function's source code. The sys module is an object which has (among other things) an attribute called path. And so forth.
Still, this begs the question. What is an object? Different programming languages define “object” in different ways. In some, it means that all objects must have attributes and methods; in others, it means that all objects are subclassable. In Python, the definition is looser; some objects have neither attributes nor methods (more on this in Chapter 3), and not all objects are subclassable (more on this in Chapter 5). But everything is an object in the sense that it can be assigned to a variable or passed as an argument to a function (more in this in Chapter 4).
總結
以上是生活随笔為你收集整理的python类属性描述_如何描述Python对象,以及属性、标识、类型和值之间的关系?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: filter函数的用法_函数周期表丨筛选
- 下一篇: python策略模式_设计模式(pyth