L = {"apple": 50, "Banana": 45};
print L.values();
>>>
[45,50]
for v in L.values:
print v;
45
50
for v in L.itervalues():
print v;
45
50
for k, v in L.items():
print k + " : " + str(v);
45
50
附帶索引值
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index, "-", name;
等於
for index, name in zip(range(1,5),L):
print index, '-', name
1 - Adam
2 - Lisa
3 - Bart
4 - Paul
歡迎轉載,請註明出處。
沒有留言:
張貼留言