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