ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(True & 2, True | 2, True ^ True, ~True)
- A. 0 3 True -2
- B. 0 2 False -2
- C. 1 3 False -2
- D. 0 3 False -2
Correct answer: D. 0 3 False -2
True acts as 1 in bitwise operations, so 1 & 2 is 0 and 1 | 2 is 3. True ^ True is False, and ~True applies the integer complement to 1, which is -2.
More Python Programming questions
- What is printed? python print(-263 // -1 == 263, abs(-263) == 263, (263) (263) > 2127, 263 263 == 2126)
- What is printed? python print(int(1e22) == 1022, int(1e23) == 1023, float(1022) == 1e22)
- What is printed? python print('{:+}'.format(-0.0), '{:+}'.format(0), '{:+.1f}'.format(-0.04), '{:+}'.format(5))
- What is printed? python print(hex(255).upper(), int('FF', 16) == 0xff, '%X' % 255 == hex(255)[2:].upper(), oct(64))
- What is printed? python print(0.1 + 0.2 != 0.3, 1 if 0.1 + 0.2 else 0, 0.0 or -0.0 or 'x', 0 and 1 or 2)
- What is printed? python print(len('u0301'), len('au0301'), 'au0301'.upper() == 'Au0301')