[objects & values & types]

1、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.

2、The ‘is‘ operator compares the identity of two objects; the id() function returns an integer representing its identity (currently implemented as its address).

3、An object’s type is also unchangeable. 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).

4、An object’s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.

5、Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected.

6、CPython implementation detail: CPython currently uses a reference-counting scheme with (optional) delayed detection of cyclically linked garbage, which collects most objects as soon as they become unreachable, but is not guaranteed to collect garbage containing circular references.

7、Some objects contain references to “external” resources such as open files or windows. It is understood that these resources are freed when the object is garbage-collected, but since garbage collection is not guaranteed to happen, such objects also provide an explicit way to release the external resource, usually a close() method. Programs are strongly recommended to explicitly close such objects. The ‘try...finally‘ statement provides a convenient way to do this.

  垃圾回收时,资源会被自动释放。但垃圾回收无法保证及时触发。所以尽量调用close() 释放释放资源。

8、For immutable types, operations that compute new values may actually return a reference to any existing object with the same type and value, while for mutable objects this is not allowed. E.g., after a = 1; b = 1, a and b may or may not refer to the same object with the value one, depending on the implementation, but after c = []; d = []c and d are guaranteed to refer to two different, unique, newly created empty lists. (Note that c = d = [] assigns the same object to both c andd.)

参考: http://docs.python.org/2.7/reference/datamodel.html#objects-values-and-types

objects & values & types的更多相关文章

  1. Django objects.values

    values(*fields) 返回一个ValuesQuerySet —— QuerySet 的一个子类,迭代时返回字典而不是模型实例对象. 每个字典表示一个对象,键对应于模型对象的属性名称. 下面的 ...

  2. ballerina 学习十四 values && types

    ballerina 包含的数据类型有string int map array record boolean ojbect function table tuple any 简单说明 数据类型和其他语言 ...

  3. Python进阶 - 对象,名字以及绑定

    Python进阶 - 对象,名字以及绑定 1.一切皆对象 Python哲学: Python中一切皆对象 1.1 数据模型-对象,值以及类型 对象是Python对数据的抽象.Python程序中所有的数据 ...

  4. The Standard Librarian: I/O and Function Objects: Containers of Pointers

    C++ Experts Forum The Standard Librarian: I/O and Function Objects: Containers of Pointers Matthew A ...

  5. django获取某一个字段的列表,values/values_list/flat

    class Building(models.Model): corporation = models.ForeignKey('company.Corporation', verbose_name=u' ...

  6. Eloquent JavaScript #01# values

    When action grows unprofitable, gather information; when information grows unprofitable, sleep.      ...

  7. django的queryset和objects对象

    1. queryset是查询集,就是传到服务器上的url里面的内容.Django会对查询返回的结果集QerySet进行缓存,这里是为了提高查询效率. 也就是说,在你创建一个QuerySet对象的时候, ...

  8. Django 二——models(admin、ORM),一对一、一对多、多对多操作,all、values、value_list的对比

    内容概要 1.关系对象映射ORM 2.admin的配置(选修) 3.all().values().value_list()的对比 4.数据库操作(一对一.一对多.多对多) 5.HttpResponse ...

  9. django获取某一个字段的列表 values values_list flat=true

    1.values() print(Question.objects.values('title')) #得到的是一个字典 <QuestionQuerySet [{'title': '查询优化之s ...

随机推荐

  1. DOM之一些小实验demo

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  2. 2018.11.28 RF基础1

    1 射频元件 高频电阻: 高频电容: 高频电感: 2 传输线 a 传输线效应:阻抗,3M法则. b 同轴线:RF中用 c 微带线: 常用: 1/4变换线 回波损耗:用网络分析仪测量 插入损耗:传输功率 ...

  3. vue.js 源代码学习笔记 ----- fillter-parse.js

    /* @flow */ export function parseFilters (exp: string): string { let inSingle = false let inDouble = ...

  4. 各开源 bbs 程序比较

    主要是集中在 php 开源轻巧的程序. 搜索到一个逼乎的一个帖子:https://www.zhihu.com/question/20655704 ,顺藤摸瓜 下. carbon forum 第一个测试 ...

  5. Python ImportError: No module named Image

    /********************************************************************************* * Python ImportEr ...

  6. Oozie_03运行官方案例【20161116】

    3.1官方的案例 (1)Oozie根目录下找到 oozie-examples.tar.gz (2)解压tar -zxvf oozie-examples.tar.gz  生成example文件夹 [ha ...

  7. Linux下软件安装方法

    1.交叉编译: ./configure --prefix=/usr/local/XXX ...... --host=armeg:./configure --prefix=/media/ubuntu/w ...

  8. nsq 安装试用

    因为是mac 系统安装试用brew install nsq 安装 brew install nsq 组件说明 nsqd 守护进程进行消息的接受,缓存以及传递消息给客户端,需要配置nsqlookupd地 ...

  9. 实用的IP地址处理模块IPy

    https://www.cnblogs.com/cherishry/p/5916935.html IPy安装 pip install IPy IP地址.网段的基本处理 IPy模块包含IP类,使用它可以 ...

  10. 显示Deprecated: Assigning the return value of new by reference is deprecated in解决办法

    很多朋友的php程序当php的版本升级到5.3以后,会出现”Deprecated: Assigning the return value of new by reference is deprecat ...