ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
d = {}
d[1.0] = 'x'
d[1] = 'y'
print(d, len(d), d[True])- A. {1.0: 'x'} 1 x
- B. {1.0: 'x', 1: 'y'} 2 y
- C. {1: 'y'} 1 y
- D. {1.0: 'y'} 1 y
Correct answer: D. {1.0: 'y'} 1 y
1 and 1.0 are the same key, so the second assignment replaces the value and keeps the original key object 1.0. Looking up True finds the same key, so it returns 'y'.
More Python Programming questions
- What is printed? python print(sorted(['b', 'a', 'c'], key=lambda s: -ord(s)))
- What is printed? python print(sorted([0.5, -0.5, 0, True, False], key=abs))
- What is printed? python print(str(2100)[:5], len(str(2100)), str(2100).count('0'))
- What is printed? python print(int('9' 5) 2 // 109, (109 - 1) 2 // 109)
- What is printed? python x = 0 for i in range(1, 101): x += i print(x, x // 2 2 == x, x % 2)
- What is printed? python print(','.join(['a', 'b']), ','.join('ab'), '%s' % ['a', 'b'], str(('a',)))