[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. 在JavaScript中进行文件处理,第一部分:基础

    译注:原文是<JavaScript高级程序设计>的作者Nicholas Zakas写的,本翻译纯属为自己学习而做,仅供参考.原文链接:这里 很多年前,我在一次Goole面试被问到,如何在w ...

  2. php http build query

    http_build_query (PHP 5, PHP 7) http_build_query — 生成 URL-encode 之后的请求字符串 说明¶ string http_build_quer ...

  3. 通过iframe 实现upload file无刷新

    <html>    <head> </head> <body> <form encType="multipart/form-data&q ...

  4. query更多的筛选用法

    比较操作符$eq : =  写法:db.class0.find({age:{$eq:18}},{name:1,_id:0}); 查找年龄等于18$lt :<$lte : <=$gt : & ...

  5. BZOJ4033: [HAOI2015]树上染色(树形DP)

    4033: [HAOI2015]树上染色 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 3461  Solved: 1473[Submit][Stat ...

  6. PAT 1007 素数对猜想 C语言

    让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数.显然有 d1=1 且对于n>1有 dn 是偶数.“素数对猜想”认为“存在无穷多对相邻且差为2的素数”. 现给定任意正 ...

  7. vue+webpack多个项目共用组件动态打包单个项目

    原文复制:https://www.jianshu.com/p/fa19a07b1496 修改了一些东西,因为sh脚本不能再window电脑执行,所以改成了node脚本.这是基于vue-cli2.0配置 ...

  8. Telnet远程重启路由器TP-LINK

    突然断网,以前房东的路由器管理页面可以打开,今天突然间就打不开了.ping了下,可以ping通,于是就想起了房东的路由器是TP-LINK的 可以 telnet登陆的.每次,断网,我都会重启房东的路由器 ...

  9. cocos2dx切换场景

    第一屏必须: auto scene = GameMenu::createScene(); director->runWithScene(scene); 然后是主场景: auto scene = ...

  10. 彻底解密C++宽字符(一)

    彻底解密C++宽字符(一) 转:http://club.topsage.com/thread-2227977-1-1.html 1.从char到wchar_t “这个问题比你想象中复杂” 从字符到整数 ...