Interactive Python Prompt

Use the interactive prompt for one quick calculation at a time, notice how it remembers earlier values, and decide when a complete saved script is clearer.

Recognize the Prompt

A local interactive session commonly begins with a prompt like this:

>>>

The three greater-than signs are supplied by Python. Type the instruction after them; do not copy >>> into a saved .py file.

An expression entered at the prompt displays its value directly:

>>> 18 + 21 + 20 + 23
82
>>> 82 / 4
20.5

In a saved program, an expression is not automatically displayed. Use print() when the program should produce visible output.

Try a Browser Prompt

The browser prompt remembers earlier values while it remains open. Enter 18 + 21 + 20 + 23, then try 82 / 4.

Interactive Python

Run one short expression or instruction at a time.

Python will start when you run the first command.

Ready to run.

Remembered Values Stay in the Session

An interactive session can remember a value for a later instruction:

>>> total = 82
>>> count = 4
>>> total / count
20.5

The first two instructions remember values but display nothing. The final expression displays its result. The remembered values disappear when the prompt is reset or closed.

Remembering earlier values can be convenient, but it can also hide which instructions a result depends on. A saved script places the complete calculation in one source file that can be run again from the beginning.

Choose Prompt or Script

Use the interactive prompt when you want to:

  • check one arithmetic expression;
  • inspect one small value;
  • test the spelling of a short instruction.

Use a saved script or the lesson editor when you want to:

  • keep several instructions together;
  • rerun the complete calculation from a clean start;
  • share or revise the source later.

At a local prompt, exit() normally ends the session. The browser prompt above can simply remain unused or be reset with the surrounding page.

References

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

Review

Not marked done.