32 lines
466 B
Plaintext
32 lines
466 B
Plaintext
for k,v in [(1,2),(3,4),(5,6)]:
|
|
print(k,v)
|
|
# 1 2
|
|
# 3 4
|
|
# 5 6
|
|
|
|
try:
|
|
for k,v,z in [(1,2,7),(3,4,8),(5,6)]:
|
|
print(k,v,z)
|
|
except:
|
|
print(exception.__class__.__name__)
|
|
# 1 2 7
|
|
# 3 4 8
|
|
# ValueError
|
|
|
|
try:
|
|
for k,v in [1,2,3]:
|
|
print("type error")
|
|
except:
|
|
print(exception.__class__.__name__)
|
|
# TypeError
|
|
|
|
for k, v in {'a': 1, 2: 'b'}.items():
|
|
print(k,v)
|
|
# a 1
|
|
# 2 b
|
|
|
|
for i in {'a': 1, 2: 'b'}.items():
|
|
print(i)
|
|
# ('a', 1)
|
|
# (2, 'b')
|