Python Programming - Debugging Questions with Answers focus on identifying and fixing code errors. These Python Debugging Questions are useful for IBM, Wipro, and SSC exams to enhance logical reasoning and problem-solving in programming
Debugging
Showing 10 of
25 questions
Questions per page:
5
10
20
50
11. What is the purpose of the "finally" block in exception handling?
Handle specific exceptions
Execute only if no exception
Execute always for cleanup
Handle syntax errors
Answer: Option
C
Hints: The finally block always executes, regardless of whether an exception occurred or not, making it ideal for cleanup operations.
Show
Answer
Hide
Answer
Report
12. Which pdb command prints the current stack trace?
Answer: Option
C
Hints: The "w" command in pdb displays the stack trace, showing the current execution point and call hierarchy.
Show
Answer
Hide
Answer
Report
13. What causes "UnboundLocalError: local variable referenced before assignment"?
Global variable access
Variable accessed before assignment
Variable name conflict
Memory allocation issue
Answer: Option
B
Hints: This error occurs when a local variable is accessed before it's assigned a value within the function.
Show
Answer
Hide
Answer
Report
14. How can you inspect variable values in pdb?
Answer: Option
C
Hints: The "p" command in pdb is used to print and inspect variable values during debugging sessions.
Show
Answer
Hide
Answer
Report
15. What is a common debugging technique for isolating issues?
Binary search debugging
Linear scanning
Random testing
Code obfuscation
Answer: Option
A
Hints: Binary search debugging involves systematically dividing the code to locate the source of an error.
Show
Answer
Hide
Answer
Report
16. Which exception is raised when a key is not found in a dictionary?
KeyError
IndexError
ValueError
NameError
Answer: Option
A
Hints: KeyError is specifically raised when trying to access a dictionary key that doesn't exist.
Show
Answer
Hide
Answer
Report
17. What does the "l" command do in pdb?
List variables
List source code
Load module
Leave debugger
Answer: Option
B
Hints: The "l" command in pdb lists the source code around the current line being executed.
Show
Answer
Hide
Answer
Report
18. What is the purpose of the "assert" statement in debugging?
Handle exceptions
Check conditions for debugging
Print debug information
Skip code execution
Answer: Option
B
Hints: assert statements are used for debugging by checking if conditions are true, raising AssertionError if false.
Show
Answer
Hide
Answer
Report
19. Which pdb command steps over function calls?
Answer: Option
B
Hints: The "n" command in pdb steps over function calls, executing them without stepping into their code.
Show
Answer
Hide
Answer
Report
20. What is "rubber duck debugging"?
Using physical tools
Explaining code to find errors
Testing with random data
Debugging hardware issues
Answer: Option
B
Hints: Rubber duck debugging involves explaining code line-by-line to an inanimate object to find logical errors.
Show
Answer
Hide
Answer
Report