ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(1 == 1.0, hash(1) == hash(1.0), {1: 'a'}[1.0], True + 1.0)- A. True False a 2.0
- B. True True None 2.0
- C. True True a 2.0
- D. 1 True a 2
Correct answer: C. True True a 2.0
1 and 1.0 are equal, and equal numbers must hash the same, so the dict lookup with 1.0 finds 'a'. True behaves as the integer 1 in arithmetic, and adding 1.0 gives the float 2.0.
More Python Programming questions
- What is printed? python print(sorted([3, -3, 2, -2, 1], key=abs))
- What is printed? python print(f'{-1.5:+.1f}', f'{0.5:.0f}', f'{1.5:.0f}', f'{-0.04:.1f}')
- What is printed? python print(format('x', '>4') + '|' + format(3.14159, '^9.2f') + '|' + format(42, '+') + '|' + format(1234567, ','))
- What is printed? python print('%d%%' % 50, '%x' % 255, '%o' % 8, '%e' % 12345.678)
- What is printed? python print(-(264) >> 3, -(264) // 8, -(264) % 10)
- What is printed? python print('a,b,,c'.split(','), 'a b c'.split(), 'a b c'.split(' '), ' x '.strip(), 'x,'.split(','))