ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(bin(-5), (-5).bit_length(), ~5, -5 >> 1, -5 & 0b111, 5 ^ -1)
- A. 0b11111011 3 -6 -2 3 -6
- B. -0b101 3 -6 -3 3 -6
- C. -0b101 3 -6 -2 3 -6
- D. -0b101 4 -5 -3 5 4
Correct answer: B. -0b101 3 -6 -3 3 -6
bin() shows negatives with a minus sign. Bitwise ops act as on infinite two's complement: ~5 = -6, -5 >> 1 floors to -3, -5 & 7 = 3 (…11011 & 111 = 011), and 5 ^ -1 = ~5 = -6.
More Python Programming questions
- What is printed? python print("10" + "5", int("10") + 5, "10" 2, str(10) 2 == "1010", "5" < "10")
- What is printed? python a = "hello" try: a[0] = "j" except TypeError: a = "j" + a[1:] b = a.replace("l", "X", 1) print(a, b…
- What is printed? python print(1000 == 1000, 0.1 + 0.7, 7 / 2 == 7 // 2 + 0.5, 2 0.5 2, (-8) (1 / 3) == -2)
- What is printed? python s = "racecar" print(s.index("c"), s.rindex("c"), s.find("c", 3), s[::-1] is s, s.count("a", 2))
- What is printed? python import sys print(type(10 20).name, 10 20 // 3 % 10, len(str(2 100)), (2 64) - 1 == 0xFFFFFFFFFFFFFFFF)
- What is printed? python x = [1, 2, 3] print(x 2, [x] 2 == [[1, 2, 3], [1, 2, 3]], x + [4] is x, [] == False, not [])