[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. zoj2314

    题解: 有上限的网络流 基本模板 代码: #include<bits/stdc++.h> using namespace std; ; int ne[N],num,n,m,d[N],S,T ...

  2. Tomcat : Invalid character found in the request target

    Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC ...

  3. Jenkins插件开发(二)-- HelloWorld

    在上一篇blog中我们讲了如何搭建jenkins插件的开发环境,接下来介绍如何开发我们的插件. 创建HelloWorld插件 学习每门新语言的时候,我们都会写一个HelloWorld程序,这里介绍的是 ...

  4. Redis集群搭建笔记

    系统为CentOS7,创建9001-9006 6个文件夹,复制 redis-server redis.conf 文件到6个新文件夹下 redis.conf文件配置如下: port 9001 daemo ...

  5. C++ readdir、readdir_r函数

    readdir, readdir_r - 读一个目录 readdir函数: struct dirent *readdir(DIR *dirp); The  data  returned by read ...

  6. java面试题9

    1.选择题 public class Test01 { public static void changeStr(String str) { str = "welcome"; } ...

  7. chrom调试javascript

    上面的文章已经大致介绍了一下console对象具体有哪些方面以及基本的应用,下面简单介绍一下如何利用好chrome控制台这个神器好好调试javascript代码(这个才是我们真正能用到实处的地方) 1 ...

  8. 树莓派(raspberry pi)系统开发

    [树莓派(raspberry pi)] 01.在linux环境下给树莓派安装系统及入门各种资料 [树莓派(raspberry pi)] 02.PI3安装openCV开发环境做图像识别(详细版) 出处: ...

  9. ThinkPHP think-migration 简洁使用教程

    ThinkPHP think-migration 简洁使用教程 migration:一种数据库的版本控制,让团队在修改数据库结构的同时,保持彼此的进度一致.帮你更简单的管理数据库.基于原生 think ...

  10. [CLPR]BP神经网络的C++实现

    文章翻译自: http://www.codeproject.com/Articles/16650/Neural-Network-for-Recognition-of-Handwritten-Digi ...