liveBook · Manning

Watch section

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

The Watch section is a debugger panel that evaluates and displays expressions selected for monitoring during execution.

The Watch section evaluates expressions you choose to monitor while the debugger pauses during execution. Add an expression with the plus sign, then inspect its changing result alongside variables and the call stack. section 8.2.2

Monitoring a word-matching condition

While debugging count_words, add "dan" in word.lower() to the Watch section. The debugger shows whether the expression is True or False for each value of word, helping you follow the function’s behavior. 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 count_words example while using a breakpoint and watched expression to follow its execution. section 8.2.2

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

How deep it goes
Defines the panel and demonstrates adding one Boolean expression, without detailing debugger internals.
Examples
Demonstrates monitoring "dan" in word.lower() while stepping through count_words.
What it assumes
Assumes familiarity with a paused Python program and debugger controls, while introducing the Watch section’s purpose from the interface.
What you can do after
Diagnose changing expression results during execution by adding watched expressions in VS Code.
How it connects
Connects watched expressions with breakpoints, variables, the call stack, and step-by-step debugging.

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.