Exercise: Debugging

Questions for: Debugging

What does the Python locals() function provide during debugging?
A:
A list of all global variables
B:
A dictionary of all local variables in the current scope
C:
Information about the call stack
D:
A list of all imported modules
Answer: B
The locals() function in Python provides a dictionary of all local variables in the current scope during debugging.
What is the purpose of the Python yield statement in relation to debugging?
A:
It sets a breakpoint in the code
B:
It enables the debugger for a specific block of code
C:
It signals the end of a debugging session
D:
It facilitates the creation of generators for step-by-step debugging
Answer: D
The yield statement in Python is used in generators and can be helpful for step-by-step debugging, allowing you to inspect the generator's state between iterations.
What does the Python __debug__ variable control during program execution?
A:
It enables or disables debugging globally
B:
It determines whether assertions are executed or ignored
C:
It checks if the Python interpreter is in debug mode
D:
It sets the verbosity level of debugging output
Answer: B
The __debug__ variable in Python controls whether assertions are executed or ignored. If it is True, assertions are executed; if False, they are ignored.
In Python, what is the purpose of the pdb.set_trace() function?
A:
To insert a breakpoint in the code for debugging
B:
To print debugging information to the console
C:
To exit the program immediately
D:
To step into a function or method call
Answer: A
The pdb.set_trace() function is used to insert a breakpoint in the code for debugging, allowing interactive debugging at that point.
In Python, what does the traceback module provide?
A:
A way to change the execution flow of the program
B:
Information about the flow of control and call stack during an error
C:
The ability to insert breakpoints in the code
D:
A graphical user interface for debugging
Answer: B
The traceback module in Python provides information about the flow of control and call stack during an error, aiding in debugging.
Ad Slot (Above Pagination)
Quiz