python学习--动态类型
#-*- coding:utf-8 -*-'''Created on 2010-8-27@author: qichen'''import sys#===============================================================================# Python中的动态类介绍:#===============================================================================#===============================================================================# 1.类型属于对象,而不是变量#===============================================================================a = 3 a = 'string'a = 1.23print type(a) #<type 'float'>#===============================================================================# 2.关于资源的回收 sys.getrefcount(3) 查询系统中,引用3个总和#===============================================================================print sys.getrefcount(3) #38(不同机器运行状况不同)a = 3b = 3print sys.getrefcount(3) #40b = 4print sys.getrefcount(3) #39#===============================================================================# 3.共享引用 同JAVA一样,String是不能改变的,而列表时可以改变的。#===============================================================================a = 'string'b = ab = b + '_type'print 'b is %s and a is %s' % (b , a) #b is string and a is string_typea = b = ab = 1print 'b is %s and a is %s' % (b , a) #b is and a is a = b = print 'a and b is same values ? %s' % (a == b) #Trueprint 'a and b is same object ? %s' % (a is b) #False
页:
[1]