ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(12 & -12, 12 & 11, ~12 & 0xF)
- A. 4 11 3
- B. 4 8 3
- C. 4 8 13
- D. 4 8 9
Correct answer: B. 4 8 3
12 & -12 isolates the lowest set bit of 12, which is 4. 12 & 11 keeps the common bits 1000, which is 8. ~12 is -13, and its low four bits are 0011, which is 3.
More Python Programming questions
- Which loop builds a list of n items in total O(n^2) time in CPython, because each step copies the whole list?
- What is printed? python s = {1, 2, 3} s |= {3, 4} s.discard(9) print(sorted(s), 4 in s, len(s))
- What is printed? python nums = [5, 3, 8] nums2 = nums nums += [1] nums3 = nums[:] nums3.pop() print(nums2, nums3)
- What is printed? python from math import gcd print(gcd(0, 5), gcd(-4, 6), gcd(0, 0))
- What is printed? python x = 12 x //= 5 y = 12 y /= 5 print(x, y, type(x).name, type(y).name)
- What is printed? python import itertools print(list(itertools.islice(itertools.cycle('ab'), 5)), list(itertools.repeat(7, 2)))