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)
  1. A. 10, 20, 0010, a
  2. B. x=10, x*2=20, 10, a
  3. C. x=10, x*2=20, 0010, a
  4. 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

Exams that ask this topic