Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.