str() — Python Technical Interview Questions & Answers

str()

str()

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

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

Code Examples for str()

Example

# str()
print(str(21) + " marks")

str() — output: 21 marks. Number became text.

How to Explain str() to an Interviewer

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

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

What does the example print, and why?

str() — output: 21 marks

What mistake do freshers make with str()?

Wrong type → TypeError.