Debugging Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
What is the purpose of the "finally" block in exception handling?
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?
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"?
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?
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?
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?
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?
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?
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?
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"?
Answer: Option B
Explanation: Rubber duck debugging involves explaining code line-by-line to an inanimate object to find logical errors.