abs() — Python Technical Interview Questions & Answers

abs()

abs()

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

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

Code Examples for abs()

Example

# abs()
print(abs(-12))
print(abs(3.5))

abs() — output: 12 then 3.5. abs drops the sign.

How to Explain abs() to an Interviewer

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

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

What does the example print, and why?

abs() — output: 12 then 3

What mistake do freshers make with abs()?

Wrong type → TypeError.