ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(4 & 3 == 0, 6 & 3 == 0)
- A. True False
- B. False False
- C. True True
- D. False True
Correct answer: A. True False
In Python the bitwise & binds tighter than ==, so this is (4 & 3) == 0 and (6 & 3) == 0. 4 & 3 is 0, and 6 & 3 is 2, which is not 0. In C the precedence is reversed, which is a common trap for Python programmers coming from C.
More Python Programming questions
- What is printed? python print(int(1e23), int(1e20))
- What is printed? python x = [3, 1, 2].sort() print(x, sorted([3, 1, 2]))
- What is printed? python print(min([(1, 'b'), (1, 'a')], key=lambda t: t[0]), max(['aa', 'b', 'cc'], key=len))
- What is printed? python d = dict.fromkeys(['a', 'b'], []) d['a'].append(1) print(d)
- What is printed? python list = [1] try: print(list(range(2))) except TypeError as e: print(e)
- What is printed? python import heapq g = {'A': [('B', 1), ('C', 4)], 'B': [('C', 2), ('D', 5)], 'C': [('D', 1)], 'D': []} dist = {k…