Debugging Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
What is the output of the following code? x = [1, 2, 3] y = x x.append(4) print(y)
  • A [1, 2, 3]
  • B [1, 2, 3, 4]
  • C [4, 3, 2, 1]
  • D Error
Answer: Option B
Explanation: When you assign y = x, both variables reference the same list object. Modifying x also affects y.
Q2
Which method is used to debug by printing variable values in Python?
  • A debug()
  • B print()
  • C log()
  • D output()
Answer: Option B
Explanation: print() is the most basic debugging technique to output variable values during execution.
Q3
What does the "NameError: name x is not defined" indicate?
  • A Syntax error in variable name
  • B Variable used before declaration
  • C Variable name is a reserved keyword
  • D Memory allocation error
Answer: Option B
Explanation: This error occurs when trying to use a variable that hasn't been declared or is out of scope.
Q4
What is the purpose of the pdb module in Python?
  • A Performance optimization
  • B Code formatting
  • C Interactive debugging
  • D Package management
Answer: Option C
Explanation: pdb (Python Debugger) provides an interactive debugging environment for Python programs.
Q5
What will be the output? try: print(10/0) except ZeroDivisionError: print("Error occurred") else: print("No error")
  • A Error occurred
  • B No error
  • C Error occurred\nNo error
  • D ZeroDivisionError
Answer: Option A
Explanation: The else block in try-except executes only if no exception occurs. Since division by zero raises an exception, else block doesn't run.
Q6
Which pdb command steps into function calls?
  • A n
  • B c
  • C s
  • D f
Answer: Option C
Explanation: The "s" command in pdb steps into function calls, while "n" steps over them.
Q7
What is a common cause of "IndexError: list index out of range"?
  • A List is empty
  • B Index is negative
  • C Accessing index beyond list length
  • D List contains mixed data types
Answer: Option C
Explanation: This error occurs when trying to access an index that doesn't exist in the list (beyond the list length).
Q8
How do you set a breakpoint in Python code using pdb?
  • A breakpoint()
  • B debug()
  • C import pdb; pdb.set_trace()
  • D set_breakpoint()
Answer: Option C
Explanation: import pdb; pdb.set_trace() is the traditional way to set breakpoints in Python code for debugging.
Q9
What does "TypeError: unsupported operand type(s)" typically indicate?
  • A Memory overflow
  • B Incompatible data types in operation
  • C Variable not defined
  • D Syntax error
Answer: Option B
Explanation: This error occurs when performing operations between incompatible data types.
Q10
Which command continues execution until the next breakpoint in pdb?
  • A s
  • B n
  • C c
  • D r
Answer: Option C
Explanation: The "c" command in pdb continues execution until the next breakpoint is encountered.
Questions and Answers for Competitive Exams Various Entrance Test