Debugging သည် code ထဲရှိ bugs များကို ရှာဖွေဖြေရှင်းခြင်း ဖြစ်သည်။
🔍 Techniques:
• Print debugging: Strategic print statements
• Python debugger (pdb): Built-in debugger
• Logging: Track program flow
• IDE debuggers: VS Code, PyCharm
💡 Tips:
• Read error messages carefully
• Use breakpoints
• Check variable values
• Test small parts
python
# Print debugging
def calculate_average(numbers):
print(f"Input: {numbers}") # Debug print
total = sum(numbers)
print(f"Total: {total}") # Debug print
avg = total / len(numbers)
print(f"Average: {avg}") # Debug print
return avg
result = calculate_average([10, 20, 30, 40])
# Using assert for debugging
def divide(a, b):
assert b != 0, "Divisor cannot be zero!"
return a / b
print(f"Division: {divide(10, 2)}")
# Logging example
import logging
logging.basicConfig(level=logging.INFO)
logging.info("Program started")
logging.warning("This is a warning")You should see
Input: [10, 20, 30, 40] Total: 100 Average: 25.0 Division: 5.0 INFO:root:Program started WARNING:root:This is a warning