# -*- 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
Python Numpy Tutorials: 元组
最新推荐文章于 2024-08-23 17:06:02 发布