ProgrammingModerateInfosys · Accenture · Capgemini pattern
What is printed?
What is printed?
print("%d items" % 3.9, int("0x1A", 16))- A. 3 items ValueError
- B. 3.9 items 26
- C. 3 items 26
- D. 4 items 26
Correct answer: C. 3 items 26
%d converts the float 3.9 to an int by truncation, giving 3. int("0x1A", 16) accepts the 0x prefix when the base is 16, and 0x1A = 16 + 10 = 26.
More Python Programming questions
- What is printed? python def f(a, b=2, c, d=4): return a + b + sum(c) + d print(f(1, 3, 5, 7, d=1))
- What is printed? python class A: def show(self): return "A" class B(A): def show(self): return "B" + super().show() print(B().show())
- What is printed? python x = [1, 2, 3] y = x[:] y[0] = 9 z = x z[1] = 8 print(x)
- What is printed? python print(sorted([3, -1, 2, -5], key=abs, reverse=True))
- What is printed? python print(list(filter(None, [0, 1, "", "a", [], [0], None])))
- What is printed? python def gen(): yield 1 return 5 yield 2 print(list(gen()))