format() — Python Technical Interview Questions & Answers

format()

format()

  • format() is built into Python. You do not import it. Freshers only need one honest call and the printed result — not a long definition.
  • format() — output: 090. Width 3, pad with zeros.
  • Wrong type often raises TypeError. Empty values matter for bool/all/any. Don’t mix format up with a similar name (sorted vs sort, int vs float).

Technical Interview Tip: Call format() once and say what prints.

Code Examples for format()

Example

# format()
print(format(90, "03d"))

format() — output: 090. Width 3, pad with zeros.

How to Explain format() to an Interviewer

Explain format() as if you are teaching a junior — definition, then one tiny script.

format() is built-in — no import. One call + exact output.

What does the example print, and why?

format() — output: 090

What mistake do freshers make with format()?

Wrong type → TypeError.