Python can execute saved script files or evaluate commands interactively. Both use the interpreter, but they suit different tasks.
Understanding the Concept
Interactive mode presents a prompt such as >>> and evaluates each expression after you press Enter. It is useful for testing a quick calculation or asking for help. Script mode runs the statements stored in a .py file from top to bottom and is better for code you want to repeat or share. In the interactive shell a bare expression usually displays its representation; in a script it normally does not display unless you use print().
When and Why You Would Use This
Try a simple expression in the REPL, then write the same expression into a script. Observe the difference. You can use PyCharm’s Python Console or a terminal-based interactive interpreter.
Practical Example
>>> 7 * 6
42
>>> print(7 * 6)
42
Understanding the Example
The >>> prefix belongs to the interactive prompt, not to Python source code. A .py file should contain print(7 * 6) without the prompt characters. The example shows the session transcript, not a script to paste directly.
Try It Yourself
Run 8 + 9 interactively, then save a script that prints the same result.
Common Beginner Mistakes
- Including >>> prompt markers inside a Python source file.
- Expecting a bare expression to print its value in script mode.
- Keeping useful work only in interactive history instead of a saved file.
Key Takeaways
- Interactive mode is designed for immediate experiments.
- Scripts store instructions for repeatable execution.
- Use print() for visible console output in script mode.