Python Strings · Question 12 · Medium

Format specifiers are used inside two f-strings. What does this print?

price = 1234.5
print(f"{price:.2f}", f"{7:03d}")
  1. 1234.50 007
  2. 1234.5 007
  3. 1234.50 7
  4. 1234.50 700
Answer and explanation

Answer: A. 1234.50 007

Explanation: .2f formats a number with exactly two digits after the decimal point, giving 1234.50. 03d pads an integer with zeros on the left to a width of 3, giving 007.

Previous: A list of integers is passed to join(). What happens when this runs? · Next: A string literal contains a tab escape and an escaped backslash. How many…

Practise python strings

Try a fresh set of python strings questions with an explanation after every answer, free and without signing up: Python Strings practice. Or sit a full placement mock test.

More python strings questions

More python practice

Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge