ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(bin(5 << 2), 5 >> 1, -5 >> 1, -5 // 2)
- A. 0b10100 2 -3 -2
- B. 0b1010 2 -3 -3
- C. 0b10100 2 -3 -3
- D. 0b10100 2 -2 -3
Correct answer: C. 0b10100 2 -3 -3
5 << 2 is 20, which is 0b10100. >> is an arithmetic shift, so -5 >> 1 floors to -3, the same as -5 // 2.
More Python Programming questions
- What is printed? python print(1 if 0 else 2 if 3 else 4, 0 or '' or 'z', 0 and 'z')
- What is printed? python a = [1, 2, 3] b = a 2 b[0] = 9 print(a, b)
- What is printed? python s = 'xxxy' print(s.rstrip('y'), s.strip('x'), repr(s.lstrip('xy')))
- What is printed? python print('abc' < 'abcd', 'Z' < 'a', '10' < '9')
- What is printed? python i = 0 while (i := i + 1) < 4: pass print(i)
- What is printed? python print(float('nan') < 0, float('inf') > 10 300, -float('inf') < -10 300)