What is the output of the following Python code? x = 3.14159; print(f”{x:.2f}|{7:03d}”)
Correct answer A. 3.14|007
Explanation
Inside an f-string the part after the colon is a format specification. .2f formats a float with exactly two digits after the decimal point, giving 3.14. 03d formats an integer in a field of width 3 padded with leading zeros, giving 007. Without the 0 flag the number would be padded with spaces instead.
Answer checked How we write and check questions
Discussion