Python2.5のFor文

感想おまちしてます!

スポンサーリンク

forをつかってみるぜ

for num in [1, 2, 3]:
print num

for (num1, num2) in ((1,1), (2,2)):
print num1 + num2

for num in range(3):
print num

str = "for"
for num in range(len(str)):
print str[num]


keys = ["1", "2", "3"]
values = ["value1", "value2", "value3"]
for (key, value) in zip(keys, values):
print key + ":" + value

実行結果

1
2
3
2
4
0
1
2
f
o
r
1:value1
2:value2
3:value3