dir() — Python Technical Interview Questions & Answers

dir()

dir()

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

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

Code Examples for dir()

Example

# dir()
print("upper" in dir(str))

dir() — output: True. dir lists attributes/methods.

How to Explain dir() to an Interviewer

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

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

What does the example print, and why?

dir() — output: True

What mistake do freshers make with dir()?

Wrong type → TypeError.