Reading and Running Code
-
Tracing Program State by Hand
A trace records the values that change as a program runs. Follow a few assignments to find the first step where the actual result differs from your expectation.
-
Expressions and Statements
A readable program makes it clear which constructs compute values and which steps change the state or direction of the computation.
-
Names, Objects, and Bindings
Understand what assignment changes, when two names share an object, and why update order matters in everyday programming.
-
Source Code, Programs, and Running Processes
A saved program can produce several independent executions, each with its own input, state, output, and lifetime.
-
Syntax Errors and Runtime Failures
Locate a failure by asking whether the language can parse the source and whether evaluation reaches a valid operation.
-
Reading a Python Traceback
Use the exception type, reported line, and chain of calls to find the inputs behind a failed operation.
-
Script and Module Entry Points
Separate definitions from the action that starts a program so that importing a tool for testing does not accidentally run it.
-
Return Values and Observable Side Effects
Identify the result delivered to the caller and the changes a call makes to its surroundings.
-
Reading Operator Precedence
Group an expression according to the language's rules, then use parentheses to make the intended calculation visible to a reader.
-
Evaluation Order and Function Arguments
Evaluation order matters when a function argument performs work, shares state, or may raise an exception before the call.
-
Naming Variables with Units and Meaning
Names carry information about units, expected state, and domain meaning that the underlying numeric or text value cannot express alone.
-
Naming Intermediate Results
An intermediate binding can reveal the source, unit, or invariant of a value and make errors easier to locate.
-
Comments That Explain a Decision
A useful comment records a domain rule or a reason a reader could not recover by following the control flow alone.
-
Reading Sample Inputs and Outputs
A sample reveals how a program represents data, chooses its boundaries, and formats its result. Interpret it before generalizing.
-
Reading and Writing Pseudocode
Pseudocode describes a procedure in terms of observable steps. Explicit indexing, mutation, and stopping rules make it precise enough to implement.
-
Choosing Testable Program Inputs
An example becomes more useful when changing one input can distinguish between two plausible implementations.
-
Input, State, and Output in a Program
Distinguish information supplied to a run from the state retained during it and the observations it emits along the way.
-
Logical Blocks and Indentation
Indentation represents control structure in Python. A one-line change in indentation can decide whether work happens once or repeatedly.
-
Local and Module-Level Name Lookup
Python resolves names using the function's lexical context. An assignment can alter which binding an earlier read in the same function uses.
-
Reproducing a Program Run
Record the parts of the environment that supply input even when they are absent from the command line.
-
Exit Status and Command Output
Programs can report a successful run separately from whatever they write to an output stream. Callers use the exit status to decide whether to continue.
-
Displaying Values as Text
A display representation can hide distinctions that matter during troubleshooting, including whitespace, types, and precision.
-
Imports and Bound Names
An import can bind a module object or a name drawn from it. That choice affects what another module observes after a subsequent assignment.
-
Command-Line Arguments Start as Text
Each command-line argument reaches an ordinary Python program as a string. A command's argument parser supplies types and reports invalid values.
-
Literals, Calculated Values, and Domain Constants
A literal supplies a concrete value in the source. A well-named constant records a policy, unit conversion, or invariant shared across calculations.
-
Small Experiments in the Python Interpreter
An interactive interpreter helps isolate an expression or check a language rule. Keep enough context to replay the experiment in a fresh session.
-
Reading a Program as a Chain of Transformations
A program that changes data through several representations is easier to inspect when each stage has a named input and output.
-
Reading Equality Checks and Updates
An assignment changes a binding. An equality expression produces a truth value that can guide a later decision.
-
Returning from a Function Call
When a function returns, its caller resumes at a pending expression or statement and can use the delivered value.
-
A Worked Python Program from Input to Result
Calculate the cost of three orders from compact text records and use the result to practice tracking intermediate state and validation.