Question discussion

What is the output of the following Python code?x = 7 print(f"{x:03d}|{x/2:.1f}|{x!r}")

1719Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Python code?

x = 7
print(f"{x:03d}|{x/2:.1f}|{x!r}")
  • A007|3|'7'
  • B7|3.5|7
  • C007|3.50|7
  • D007|3.5|7
Correct answer: D

Explanation

The format 03d pads 7 with zeros to 007, .1f shows 3.5, and !r applies repr to the integer 7, which is still 7.

Discussion 0

Nobody has replied yet. Start the discussion!