ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(bool(0.0 or 0j), bool(0j or 1j), 0j == 0, 1j * 1j)
- A. True True False (-1+0j)
- B. False False True (1+0j)
- C. False True True (2+0j)
- D. False True True (-1+0j)
Correct answer: D. False True True (-1+0j)
0.0 and 0j are both falsy, but 1j is not. A complex zero equals the integer 0, and 1j * 1j is -1 with a zero imaginary part.
More Python Programming questions
- What is printed? python print([x for x in range(5) if x % 2], [x for x in 'a1b2' if x.isdigit()], {x % 3 for x in range(6)})
- What is printed? python print(str(()), str([()]), repr(('a',)), str(('a', 1)))
- What is printed? python x = 10 def f(): return x x = 20 print(f(), (lambda y=x: y)(), [lambda: i for i in range(2)][1]())
- What is printed? python print(list(map(int, '1 2 3'.split())), list(map(str.upper, 'ab')), sum(map(int, '9' 3)) % 7)
- What is printed? python print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 1e-5, '%G' % 1e-10)
- What is printed? python print(max([1, 2], [1, 2, 0]) == [1, 2, 0], min((1, 'a'), (1, 'b')), sorted([(1, 'b'), (1, 'a')])[0][1])