Concepts / Python Data Types and Expressions

Python Data Types and Expressions

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

  • Programming

Opening a Conversation with Python

Learning Python syntax on paper is only part of the work. To test commands, investigate mistakes, and see what Python does with an expression, you need to run the interpreter. Interactive mode makes this possible one command at a time: you enter a command, see Python's response immediately, and then continue with another command.

Before starting, Python must be installed on your machine. Open a terminal or command window, then type python and press Enter. The exact way to open a terminal differs by operating system, but the purpose is the same: provide a text-based interface for entering commands.

python
Terminalcommand windowpythontyped commandPython interpreterstartsVersion informationdisplayed>>> promptready for a commandtypepress Enterdisplaysthen shows
How does control move from typing python in a terminal to Python displaying version information and the >>> prompt?

Reading the Ready Signal

When the interpreter starts, Python displays a welcome message that includes version information and brief help text. The most important part for your next action is the >>> prompt. It is Python's signal that the interpreter is ready to receive your command.

The prompt is also a status indicator. When >>> is visible, Python is waiting for input. If it is missing or replaced by something else, Python may still be processing the previous command, or something may have gone wrong. The prompt tells you when it is appropriate to enter the next command.

Terminalready for pythonInterpreter runningstartup informationdisplayed>>> promptwaiting for inputtype pythonstartup completes
What changes when Python moves from starting up to waiting for a learner's command?

Evaluating a Simple Expression

Once >>> appears, enter a simple mathematical expression. The source example uses 2 + 3. After you press Enter, Python evaluates the arithmetic and displays 5 on the next line. A new >>> prompt then appears.

Code walkthrough
>>> 2 + 3
5
>>>
  1. 1
    At the first prompt, enter 2 + 3 and press Enter.
  2. 2
    Python evaluates the mathematical expression.
  3. 3
    Python prints the result 5.
  4. 4
    Python displays a new >>> prompt and waits for the next command.
  • The first >>> is printed by Python; do not type it.
  • 2 + 3 is the command entered by the learner.
  • 5 is the result Python displays.
  • The new >>> shows that Python is ready for another command.
Output
5
Worked example

Following One Interaction

What happens when the command 2 + 3 is entered at the >>> prompt?

  1. 1
    Enter

    The learner types 2 + 3 at the visible >>> prompt and presses Enter.

  2. 2
    Evaluate

    Python evaluates the arithmetic expression.

  3. 3
    Print

    Python displays the result 5 on the following line.

  4. 4
    Wait

    A new >>> prompt appears, signaling that Python is ready for another command.

Result

The interaction produces 5 and returns to the >>> prompt.

The Repeating Interaction Cycle

Interactive mode follows a repeating read-evaluate-print cycle. Python reads the command you enter, evaluates it, prints the result, and displays a new >>> prompt. The cycle then waits for your next command. The 2 + 3 interaction is one complete pass through this cycle.

ReadcommandEvaluateexpressionPrintresult>>> promptwait for inputprocessproducedisplaynext command
What happens after a command is entered, and how does Python repeatedly read, evaluate, print, and wait for the next command?

This cycle is what makes interactive mode useful for learning and debugging. Instead of writing a complete script and running everything at once, you can try one command, inspect the immediate result, and then decide what to enter next.

Mistakes at the Prompt

  • Common mistake

    Typing the >>> characters as part of the command

    What it looks like
    >>> >>> 2 + 3
    Why it fails

    The >>> characters are Python's displayed prompt, not part of the command you should enter.

    Do this instead

    Enter only 2 + 3 when the >>> prompt is visible.

  • Common mistake

    Entering a command before Python is ready

    What it looks like

    Typing while startup information is still being displayed

    Why it fails

    The visible >>> prompt is the signal that Python is ready to receive input.

    Do this instead

    Wait until >>> appears before entering the next command.

  • Common mistake

    Assuming the interaction ends after the result appears

    What it looks like

    Stopping after seeing 5

    Why it fails

    Interactive mode displays a new prompt after evaluation so that you can continue the conversation.

    Do this instead

    Look for the new >>> prompt and use it to enter another command.

Prompt Practice

EASY

Describe the four stages that occur after you enter a command at the >>> prompt and press Enter. Then explain what the next >>> prompt tells you.

Hints
  • Begin with what Python does with the command you entered.
  • Include the result shown by Python.
  • Finish by explaining the meaning of the new prompt.
EASY

Imagine that Python has just displayed 5 after evaluating 2 + 3. What should appear next, and what action is now available to you?

Hints
  • The interactive cycle does not stop at the printed result.
  • The prompt itself is the status signal.

Essential Takeaways

  1. 1
    Type python in a terminal and press Enter to start the Python interpreter in interactive mode.
  2. 2
    Python displays version information and then shows the >>> prompt when it is ready for a command.
  3. 3
    Type only your command; the >>> prompt is displayed by Python.
  4. 4
    After a command is entered, Python reads it, evaluates it, prints the result, and displays a new >>> prompt.
  5. 5
    The repeated read-evaluate-print cycle lets you experiment with expressions and inspect results immediately.

At a glance

  • Interactive mode is started from a terminal by typing python and pressing Enter.
  • The >>> prompt means that Python is ready to receive input.
  • A command such as 2 + 3 is evaluated, its result 5 is printed, and a new prompt appears.
  • Interactive Python repeatedly follows the read-evaluate-print cycle.
  • Recognizing the prompt helps you know when to type and whether Python is ready for the next command.

Related concepts

More concepts starting with P