My Day✳All blog articles ↗

Separate a return value from printed output

Keep the text printed by a function apart from the value received by its caller.

A function’s printed text need not be its return value. Trace both channels separately; the visible number is not automatically assigned to the variable receiving the call.

Printed text: 7; returned integer: 3
Printed text: 7; returned integer: 3

What to do

  1. Copy the code with its actual indentation and locate the call while retaining execution order.
  2. Record standard-output text separately from the value that return passes back to the calling assignment.
  3. Check for extra printing or interactive automatic display, and label a manual trace as manual.

Example

Fictional practice script: def sample(): print(7) return 3 result = sample() For 1 call, print writes text 7 followed by a newline, while result receives integer 3. There is no additional print(result) or assumed interactive display. This is a manual trace from Python’s rules, not a reported execution.

My Day · Windows

In My Day, save and reopen the comparison as a text note; check the content yourself.

Buy My Day for Windows ↗