ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
x = 10
s = f"{x=}, {x*2=}, {x:04}, {'a' if x > 5 else 'b'}"
print(s)- A. 10, 20, 0010, a
- B. x=10, x*2=20, 10, a
- C. x=10, x*2=20, 0010, a
- D. x=10, 20, 0010, a
Correct answer: C. x=10, x*2=20, 0010, a
The = specifier (3.8+) prints the expression text, '=', and the value; this works for any expression such as x*2. :04 pads with zeros to width 4. A conditional expression is allowed inside the braces.
More Python Programming questions
- What is printed? python def f(): yield 1 g = f() print(type(f).name, type(g).name, hasattr(g, "next"), iter(g) is g, callable(g))
- What is printed? python class Matrix: def init(self, r): self.r = r def getitem(self, idx): i, j = idx return self.r[i][j] def…
- What is printed? python a = [1, 2, 3] b = a[:] print(a == b, a is b, a[:] is a[:], id(a) == id(b), a.copy() == list(a))
- A service catches errors with except Exception: around its main loop. Which of the following will NOT be caught by that handler?
- For a Python list a with n elements, which operation is O(n) in the worst case (not amortised O(1))?
- How many of these statements about CPython are correct? 1. A tuple is hashable only if all its elements are hashable. 2. x in someset is…