ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(7 & 3 | 4 ^ 1)
- A. 1
- B. 7
- C. 3
- D. 5
Correct answer: B. 7
In Python & binds tighter than ^, and ^ binds tighter than |. So the expression is (7 & 3) | (4 ^ 1) = 3 | 5 = 7.
More Python Programming questions
- What is printed? python print(5 <= 5 < 6 != 7, 1 < 2 > 3)
- What is printed? python print(len('') or 'empty', [] or 'none')
- What is printed? python a = [1, 2, 3] b = a[:] a.append(4) print(len(a), len(b))
- What is printed? python print(list(filter(lambda s: s.startswith('a'), ['ab', 'ba', 'ac'])), ' a b '.strip().split(' '))
- What is the time complexity of x in d where d is a collections.deque of n items?
- What is printed? python x = 10 print(x.bitlength(), (x >> 1).bitlength(), (x << 3) // 16)