Tuple数据类型:
mixed_tuple = (1 , 2, [‘a‘,‘b‘])
print("mixed_tuple:" + str(mixed_tuple))
mixed_tuple[2][0]=‘c‘
mixed_tuple[2][1]=‘d‘
print("mixed_tuple after:" + str(mixed_tuple))
字典的应用:
# coding: utf-8
# 创建一个词典
phone_book= {‘Tom‘:123,‘sunliyuan‘:456,‘shi‘:789}
mixed_dict={"Tom":‘boy‘,11:23.5}
# 字典的调用
print ("sunliyuan has phone numbr:"+ str(phone_book["sunliyuan"]))
# 修改字典的值
phone_book[‘sunliyuan‘]=521
print ("sunliyuan has phone numbr:"+ str(phone_book["sunliyuan"]))
# 添加一个值
phone_book[‘sunli‘]=888
print ("sunliyuan has phone numbr:"+ str(phone_book))
# 删除字典中的元素和本身
del phone_book[‘sunli‘]
print ("sunli after del is:"+ str(phone_book))
# 清空字典的值
phone_book.clear()
print ("sunli after del is:"+ str(phone_book))
# 清空字典本身
del phone_book
print ("sunli after del is:"+ str(phone_book))
运行的效果图:

# 特性
# 不允许同一个键出现两次
rep_test={‘Name‘:‘aa‘,‘age‘:5,‘Name‘:‘sun‘}
print("rep_test:"+str(rep_test))
# 键必须不可变 用数字和字符串充当键 不能用list充当
# list_dict={[‘Name‘]:‘sun‘,‘Age‘:13}
#Tuple是可以的 (可变的)
list_dict={(‘Nam‘):‘sun‘,‘Age‘:13}

原文:http://www.cnblogs.com/sunliyuan/p/6308908.html