Debugging Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
What is the purpose of the "finally" block in exception handling?
  • A Handle specific exceptions
  • B Execute only if no exception
  • C Execute always for cleanup
  • D Handle syntax errors
Answer: Option C
Explanation: The finally block always executes, regardless of whether an exception occurred or not, making it ideal for cleanup operations.
Q12
Which pdb command prints the current stack trace?
  • A p
  • B s
  • C w
  • D t
Answer: Option C
Explanation: The "w" command in pdb displays the stack trace, showing the current execution point and call hierarchy.
Q13
What causes "UnboundLocalError: local variable referenced before assignment"?
  • A Global variable access
  • B Variable accessed before assignment
  • C Variable name conflict
  • D Memory allocation issue
Answer: Option B
Explanation: This error occurs when a local variable is accessed before it's assigned a value within the function.
Q14
How can you inspect variable values in pdb?
  • A i
  • B v
  • C p
  • D d
Answer: Option C
Explanation: The "p" command in pdb is used to print and inspect variable values during debugging sessions.
Q15
What is a common debugging technique for isolating issues?
  • A Binary search debugging
  • B Linear scanning
  • C Random testing
  • D Code obfuscation
Answer: Option A
Explanation: Binary search debugging involves systematically dividing the code to locate the source of an error.
Q16
Which exception is raised when a key is not found in a dictionary?
  • A KeyError
  • B IndexError
  • C ValueError
  • D NameError
Answer: Option A
Explanation: KeyError is specifically raised when trying to access a dictionary key that doesn't exist.
Q17
What does the "l" command do in pdb?
  • A List variables
  • B List source code
  • C Load module
  • D Leave debugger
Answer: Option B
Explanation: The "l" command in pdb lists the source code around the current line being executed.
Q18
What is the purpose of the "assert" statement in debugging?
  • A Handle exceptions
  • B Check conditions for debugging
  • C Print debug information
  • D Skip code execution
Answer: Option B
Explanation: assert statements are used for debugging by checking if conditions are true, raising AssertionError if false.
Q19
Which pdb command steps over function calls?
  • A s
  • B n
  • C o
  • D f
Answer: Option B
Explanation: The "n" command in pdb steps over function calls, executing them without stepping into their code.
Q20
What is "rubber duck debugging"?
  • A Using physical tools
  • B Explaining code to find errors
  • C Testing with random data
  • D Debugging hardware issues
Answer: Option B
Explanation: Rubber duck debugging involves explaining code line-by-line to an inanimate object to find logical errors.
Questions and Answers for Competitive Exams Various Entrance Test