Deeper walkthroughRead The Python Interpreter Scripts and Notebooks as a mechanism, not a recipe
Treat this as a sequence of observable decisions rather than one opaque command. Stage 1: Interactive interpreter: Python shows a prompt such as >>>, executes one entered statement or expression, and keeps names in memory for the rest of that session. Stage 2: Script mode: the interpreter reads statements from a .py file in program order. Expressions are evaluated, but they are not automatically displayed; use print() or logging when visible output is required. Stage 3: Notebook mode: code is organised into cells that share one kernel state. A later cell can use objects created by an earlier executed cell even when the visible cell order is different. Final checkpoint: Reproducibility check: a notebook should still work after Restart Kernel + Run All; a script should work in a clean environment with its dependencies declared.
MechanismFollow the transformation
Interactive interpreter: Python shows a prompt such as >>>, executes one entered statement or expression, and keeps names in memory for the rest of that session.
Script mode: the interpreter reads statements from a .py file in program order. Expressions are evaluated, but they are not automatically displayed; use print() or logging when visible output is required.
Notebook mode: code is organised into cells that share one kernel state. A later cell can use objects created by an earlier executed cell even when the visible cell order is different.
EvidenceKnow what would convince you
Compare the same calculation in three environments. In the interactive interpreter, typing an expression displays its value. In a script, a standalone expression has no visible output. In a notebook, the last expression in a cell is normally displayed, and cell execution order determines the current state.
- Run the operation on a tiny literal input and write the expected type/value before executing it.
- Inspect the relevant object state before and after the operation, especially when mutable objects are involved.