ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(~0, ~-1, -~0, ~~5, -~-5)
- A. -1 0 -2 5 -4
- B. -1 0 1 5 -4
- C. -1 0 1 -6 4
- D. -1 1 1 5 4
Correct answer: B. -1 0 1 5 -4
~x equals -x - 1, so ~0 is -1 and ~-1 is 0. -~0 is -(-1) = 1, ~~5 is 5, and -~-5 is -(4) = -4.
More Python Programming questions
- What is printed? python print(max(map(int, '3 17 9'.split())), min(map(int, '3 17 9'.split())), sorted('3 17 9'.split())[-1])
- What is printed? python print(sorted(['1.10', '1.9', '1.10.1'], key=lambda v: tuple(map(int, v.split('.')))))
- What is printed? python print(sorted(['1.10', '1.9', '1.10.1']))
- What is printed? python values = [2.0, 2, '2'] print(len(set(values[:2])), len(set(values)), values[0] == values[1] == 2)
- What is printed? python t = 3 print(t // 2 if t % 2 else t / 2, 1 if t else 0, t and 0, t or 0, not t)
- What is printed? python print(int(0.999999999999999999999), round(0.4999999999999999), round(-0.4999999999999999), int(-0.9))