objects & values & types
[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的更多相关文章
- Django objects.values
values(*fields) 返回一个ValuesQuerySet —— QuerySet 的一个子类,迭代时返回字典而不是模型实例对象. 每个字典表示一个对象,键对应于模型对象的属性名称. 下面的 ...
- ballerina 学习十四 values && types
ballerina 包含的数据类型有string int map array record boolean ojbect function table tuple any 简单说明 数据类型和其他语言 ...
- Python进阶 - 对象,名字以及绑定
Python进阶 - 对象,名字以及绑定 1.一切皆对象 Python哲学: Python中一切皆对象 1.1 数据模型-对象,值以及类型 对象是Python对数据的抽象.Python程序中所有的数据 ...
- 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 ...
- django获取某一个字段的列表,values/values_list/flat
class Building(models.Model): corporation = models.ForeignKey('company.Corporation', verbose_name=u' ...
- Eloquent JavaScript #01# values
When action grows unprofitable, gather information; when information grows unprofitable, sleep. ...
- django的queryset和objects对象
1. queryset是查询集,就是传到服务器上的url里面的内容.Django会对查询返回的结果集QerySet进行缓存,这里是为了提高查询效率. 也就是说,在你创建一个QuerySet对象的时候, ...
- Django 二——models(admin、ORM),一对一、一对多、多对多操作,all、values、value_list的对比
内容概要 1.关系对象映射ORM 2.admin的配置(选修) 3.all().values().value_list()的对比 4.数据库操作(一对一.一对多.多对多) 5.HttpResponse ...
- django获取某一个字段的列表 values values_list flat=true
1.values() print(Question.objects.values('title')) #得到的是一个字典 <QuestionQuerySet [{'title': '查询优化之s ...
随机推荐
- hdu5575
题解: 每一次最短的那块板合并 先装水到溢出 然后合并 代码: #include<cstdio> #include<cstring> #include<algorithm ...
- FIS 的思想和优点
资源表 各种性能优化算法的加载框架 依赖声明有助于组件化 资源自动合并 链接 与webpack对比
- CNN中卷积层的计算细节
原文链接: https://zhuanlan.zhihu.com/p/29119239 卷积层尺寸的计算原理 输入矩阵格式:四个维度,依次为:样本数.图像高度.图像宽度.图像通道数 输出矩阵格式:与输 ...
- Codeforces 106A:Card Game
题目链接http://codeforces.com/contest/106/problem/A 题意:一套牌有S.H.D.C四种花色,按等级分成6.7.8.9.T.J.Q.K.A.每次选出一个花色作为 ...
- Windows下Java JDK8配置环境变量
JDK最新版已经出到了jdk8u60,下载安装完成后,还需要配置环境变量,下面小编就给大家分享下jdk 8.0的环境变量配置教程,希望大家喜欢. jdk8.0环境变量配置教程 右键选择 计算机→属性→ ...
- streamsets geoip 使用
geoip 分析对于网站数据分析是很方便的 安装geoip2 下载地址 https://dev.maxmind.com/geoip/geoip2/geolite2/ 配置streamsets geoi ...
- cocos2dx Scene,Layer,Sprite的理解
layer,scene,sprite的默认锚点都是0.5,0.5 三者都继承自Node节点,暂时没看出有什么区别,或者下面的话是对的吧. 在cocos2d-x中,一个应用可以有多个scene,但任何时 ...
- Loararunner录制脚本
LoadRunner录制 1.启动LoadRunner,用管理员方式打开,选择 “Create/Edit Scripts” 2.从这两个方式任意方式打开脚本页面 3.选择协议,这里我们举例子,用“We ...
- Tomcat的最大并发数
日常应用中,单台Tomcat能支持最大的并发数是多少? 作为一个有经验的Java Web开发人员对这个问题应该有大概的印象,并会让问题再具体点,比如Tomcat版本,运行模式,并发请求允许的最大响应时 ...
- dell R730 安装windwos 2008 R2在windows loading files...完成后屏幕无信号(iDrac绿屏)
dell R730 安装windwos 2008 R2在windows loading files...完成后,Starting Windows时屏幕无信号(iDrac绿屏) 解决方法: F2 进行 ...