标签:长度 enumerate 开始 while range 字典 循环 items bre
while 1=1:
pass
else:
pass
pass:一个什么都不做的占位符,防止函数或者循环语句置空报错
t = [(1,2),(3,4),(5,6)]
for (a,b) in t
print (a,b)
d = {'a'=1,'b'=2,'c'=3}
for key in d :
print (key,'>',d[key])
for (key,value) in d.items():
print (key,'>',value)
range(2,-10,-1)从2开始,到-10结束(不包括10),倒序取值,需注意步长的符号选择,如果步长为1将取不到值
l1 = [1,2,3,4,5]
l2 = [6,7,8,9,10]
list(zip(l1,l2)) #[(1, 6), (2, 7), (2, 7), (3, 8), (4, 9), (5, 10)]
set(zip(l1,l2)) #{(2, 7), (5, 10), (4, 9), (3, 8), (1, 6)}
tupl(zip(l1,l2)) #((1, 6), (2, 7), (3, 8), (4, 9), (5, 10))
l1 = [1,2,3,4,5]
l2 = [6,7,8,9,10]
d = dict(zip(l1,l2)
l1 = "abcd"
list(enumerate(l1)) #[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]
tuple(enumerate(l1)) #((0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'))
dict(enumerate(l1)) # {0: 'a', 1: 'b', 2: 'c', 3: 'd'}
list(enumerate(l1)) # {(4, 'd'), (6, 'd'), (10, 'c'), (11, 'c'), (2, 'a'), (5, 'd'), (8, 'f'), (3, 'a'), (0, 's'), (9, 'c'), (1, 's'), (7, 'f'), (12, 'a')}
python学习手册:第十三章——while循环和for循环
标签:长度 enumerate 开始 while range 字典 循环 items bre
原文地址:https://www.cnblogs.com/yingyingdeyueer/p/11852917.html