列表:
list1 = ['physics', 'chemistry', 1997, 2000]
list2 = [1, 2, 3, 4, 5, 6, 7 ]
print "list1[0]: ", list1[0] ==》list1[0]: physics
print "list2[1:5]: ", list2[1:5] ===》[2, 3, 4, 5]
元组:
tup1 = ('physics', 'chemistry', 1997, 2000)
tup2 = (1, 2, 3, 4, 5, 6, 7 )
print "tup1[0]: ", tup1[0] ==》physics
print "tup2[1:5]: ", tup2[1:5] ====》(2,3,4,5)
字典:
d = {key1 : value1, key2 : value2 }
键一般是唯一的,如果重复最后的一个键值对会替换前面的,值不需要唯一
值可以取任何数据类型,但键必须是不可变的,如字符串,数字或元组。不能是列表
dict = {['Name']: 'Zara', 'Age': 7} 不可以
不允许同一个键出现两次。创建时如果同一个键被赋值两次,后一个值会被记住
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
dict['Age'] = 8 # 更新
dict['School'] = "RUNOOB" # 添加
print "dict['Age']: ", dict['Age'] ===》8
print "dict['School']: ", dict['School'] ===》EUNOOB