python的list格式是 t=[1,2],可以随时添加或删除里面元素
python的tuple格式是t=(1,2),一旦定义就不可以修改
以下转载自Eric2016_Lv
# -*- coding: utf-8 -*-
"""
Python Version: 3.5
Created on Mon May 8 17:04:45 2017
E-mail: Eric2014_lv@sjtu.edu.cn
@author: DidiLv
"""
d = {(x, x + 1): x for x in range(10)} # Create a dictionary with tuple keys
print(d)
t = (5, 6) # Create a tuple
print(type(t)) # Prints "<type 'tuple'>"
print(d[t]) # Prints "5"
print(d[(1, 2)]) # Prints "1"
# 这只是一个结合的dictionary的表示,没啥难的
# 元组不是一个可以迭代的,更改的容器
# 输出为:
#{(0, 1): 0, (1, 2): 1, (5, 6): 5, (2, 3): 2, (4, 5): 4, (6, 7): 6, (8, 9): 8, (9, 10): 9, (3, 4): 3, (7, 8): 7}
#<class 'tuple'>
#5
#1