2.10.1.3 Common Debugging Techniques
Python Programming
- Print Statements: Adding print statements to check the values of variables at different stages of the code.
- Debugging Tools: Using tools like pdb (Python Debugger) to step through the code, inspect variables, and understand the flow of execution.
- Error Messages: Reading and interpreting error messages to locate the source of the problem.
Example: In this example, the divide function is called with a zero denominator, causing a ZeroDivisionError. The try-except block catches the error and prints an error message, helping to identify and handle the issue.
def divide(a, b) :
return a / b
try :
result = divide (10 , 0)
except ZeroDivisionError as