# encoding=utf-8
_list = []
_dict = {'a': 1, 'b': 2}
# test
_list.append(_dict)
print 'before change for list:', _list
_dict.update({'a': 100})
print 'after change for list:', _list
print '*'*10
# 说明对于可变对象list,是传的应用ref;会随着改变。
# 不可变对象,是传的值
_r_list = [1, 2]
_tuple = tuple(_r_list)
print 'before change for tuple:', _tuple
_r_list.append(3)
print 'after change for tuple:', _tuple
# 理解如下
_dict = {'a': -1}
_list = []
for i in range(3):
_dict.update({'a': i})
_list.append(_dict)
print 'result:', _list
# result: [{'a': 2}, {'a': 2}, {'a': 2}]
网友评论