What is the output of the following snippet?
What is the output of the following snippet?
dct = {}
dct[‘1’] = (1, 2)
dct[‘2’] = (2, 1)
for x in dct.keys():
print(dct[x][1], end=”)
A . 21
B. (2,1)
C. (1,2)
D. 12
Answer: A
Explanation:
Topics: dictionary tuple indexing for dict.keys() print()
Try it yourself:
dct = {}
dct[‘1’] = (1, 2)
dct[‘2’] = (2, 1)
print(dct) # {‘1’: (1, 2), ‘2’: (2, 1)}
for x in dct.keys():
print(dct[x][1], end=”) # 21
print()
print(dct[‘1’][1]) # 2
print(dct[‘2’][1]) # 1
dct.keys() are the keys ‘1’ and ‘2’
dct[‘1’][1] is 2 and
dct[‘2’][1] is 1
Latest PCEP-30-01 Dumps Valid Version with 124 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments