Built-in exceptions — Python Technical Interview Questions & Answers
Built-in exceptions
Built-in exceptions
- Python ships named errors for common failures. ValueError: int("Asha"). TypeError: 1 + "a". IndexError: list[99]. KeyError: dict missing key. FileNotFoundError: open missing path. ZeroDivisionError: 10/0. Exception is a common parent. Catch the type you expect, not a bare except.
- Name five and one cause each. That is the viva. Matching name → cause scores more than reciting the hierarchy.
- Built-in exceptions — output: ValueError. int("Asha") is the classic cause.
try: 10 / 0
│ ZeroDivisionError
▼
except → Cannot divide
│
▼
finallyTechnical Interview Tip: Five names + one cause each.
Code Examples for Built-in exceptions
Example
# Built-in exceptions
try:
int("Asha")
except ValueError as e:
print(type(e).__name__)
Built-in exceptions — output: ValueError. int("Asha") is the classic cause.
How to Explain Built-in exceptions to an Interviewer
Explain Built-in exceptions as if you are teaching a junior — definition, then one tiny script.
ValueError / TypeError IndexError / KeyError
What does the example print, and why?
Built-in exceptions — output: ValueError
What mistake do freshers make with Built-in exceptions?
ValueError / TypeError