liveBook · Manning

Visual Studio Code debugger

As explained in Learn AI-Assisted Python Programming, Second Edition

The Visual Studio Code debugger is the integrated debugging facility that controls program execution and exposes runtime state in the editor.

The Visual Studio Code debugger helps you understand program behavior by pausing execution, inspecting values, and moving through relevant lines one at a time. section 8.2.2

A practical debugging workflow is:

  • Set a breakpoint by clicking to the left of a relevant line. section 8.2.2
  • Choose Run > Start Debugging. section 8.2.2
  • Use step-by-step execution to inspect variable values and follow the code path. section 8.2.2

Tracing an incorrect word counter

Debug a count_words function with the inputs ["Dan", "danger", "Leo"]. Pause at the function, step through the loop and condition, and watch count change as each word is processed. section 8.2.2

Listing 8.4 Incorrect count_words function for debugging
def count_words(words): 
    count = 0 
    for word in words: 
        if "dan" in word.lower(): 
            count += 1 
    return count 

words = ["Dan", "danger", "Leo"]     #1
print(count_words(words))            #1

Inspect the intentionally incorrect count_words example used for breakpoint and line-by-line debugging. section 8.2.2

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Explains breakpoint setup, debugger startup, and line-by-line stepping, while focusing on common features rather than the full tool.
Examples
Demonstrates an incorrect count_words function using a short list of names and words.
What you can do after
Diagnose code behavior by setting breakpoints, stepping through execution, and inspecting changing values.
How it connects
Connects debugging with breakpoints, variable inspection, watch expressions, and step-over execution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.