Concepts / Variables and Assignment in Interactive Mode

Variables and Assignment in Interactive Mode

Start the Python interpreter by typing 'python' in a terminal; Python will display version information and a >>> prompt.

  • Programming

Starting the Conversation

Interactive mode gives you a live conversation with Python. Instead of writing a complete script and running it all at once, you enter one command, see what Python does immediately, and then decide what to try next. This makes interactive mode useful for experimenting, testing ideas, and investigating mistakes while you learn.

  1. Make sure Python is installed on your machine.
  2. Open a terminal or command window.
  3. Type python and press Enter.
  4. Wait for Python to display its version information and welcome text.
  5. Look for the >>> prompt.
typepress Enterdisplay version information, then promptTerminalready for inputpythontyped and submittedPython interpreterstarts>>>ready for a command
How does control move from typing python in a terminal to seeing the Python version information and the >>> prompt?

Reading the Prompt

The >>> prompt is Python's readiness signal. When it is visible, Python is waiting for you to enter a command. Type your command after the prompt and press Enter. Do not type the >>> characters themselves; Python displays them for you.

type commandpress Enterevaluation finishesWaiting>>> visibleCommand enteredpress EnterEvaluatingPython processes thecommandWaitingnew >>> visible
What does the >>> prompt signal about Python's current state and when you can enter a command?

Tracing One Command

Evaluating a Simple Expression

What happens when you enter the mathematical expression 2 + 3 at the Python prompt?

Enter the command: At the visible >>> prompt, type only 2 + 3 and press Enter. The prompt itself was printed by Python and is not part of what you type.

Python evaluates it: Python processes the arithmetic expression.

The result appears: The result 5 is displayed on the following line.

The prompt returns: A new >>> prompt appears, showing that Python is ready for another command.

The command produces 5, and the new >>> prompt marks the beginning of the next interaction.

python
Output
5
>>>
press Enterproducethen display2 + 3entered by learnerEvaluatePython processes theexpression5displayed result>>>ready for the next command
Where does a command go after you type it at the >>> prompt, and what appears before Python presents the next prompt?

The Read-Evaluate-Print Cycle

Interactive mode repeats one consistent cycle. Python reads the command you enter, evaluates it, prints the result, and displays a new >>> prompt. The returned prompt is important because it marks the start of the next cycle. This immediate sequence is what makes interactive mode different from running a script all at once: you can observe each command's result before entering another command.

command receivedevaluation completesresult displayednext commandReadreceive your commandEvaluateprocess the commandPrintshow the result>>>wait for the next command
What happens after you enter a command at the >>> prompt, and how does Python read, evaluate, display the result, and wait for the next command?

The cycle is not finished when the result appears. It is complete when the new >>> prompt returns. That prompt tells you Python has finished evaluating the previous command and is ready to receive another one.

Mistakes at the Prompt

  • Typing the >>> characters as part of the command.

    The >>> characters are Python's prompt, not characters that you should enter.

    Fix: Type only 2 + 3 after the prompt that Python has already displayed.

  • Entering a command before Python is ready.

    The visible prompt is the signal that Python is waiting for input. If it is missing or replaced, Python may still be processing a command or something may have gone wrong.

    Fix: Wait for the >>> prompt to appear before entering the next command.

  • Assuming interactive mode displays the next prompt before the result.

    Python evaluates the command and prints its result before showing a new >>> prompt.

    Fix: Read the result first, then use the returned prompt as the signal for the next command.

Use the prompt as a rhythm for your work: see >>>, enter one command, press Enter, inspect the result, and wait for >>> to return. This habit helps you distinguish a ready interpreter from one that is still processing a previous command.

Try the Cycle Yourself

EASY

In a terminal, start Python by typing python and pressing Enter. When the >>> prompt appears, enter 2 + 3 without typing the prompt characters. Before pressing Enter, predict what will appear first and what will appear afterward. Then compare your observation with the read-evaluate-print cycle.

Hints
  • The first visible result comes from evaluating the expression.
  • The new >>> prompt appears after the result.
  1. Interactive mode is a live environment for testing Python commands one at a time. You start it by typing python in a terminal. Python then displays version information and the >>> prompt. The prompt means that Python is ready for input, and you should type only your command after it. Each interaction follows the same pattern: Python reads your command, evaluates it, prints the result, and displays a new >>> prompt.

Key Takeaways

  • Type python in a terminal to start Python's interactive interpreter.
  • Python displays version information and then the >>> prompt.
  • The >>> prompt means Python is ready to receive a command; do not type the prompt yourself.
  • Interactive mode follows a read-evaluate-print cycle: read, evaluate, print the result, and show a new prompt.
  • The returned >>> prompt signals that the previous command is complete and the interpreter is ready for the next command.