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
typepress Enterdisplaysthen showsTerminalcommand windowpythontyped commandPython interpreterstartsVersion informationdisplayed>>> promptready for a command
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.

type pythonstartup completesTerminalready for pythonInterpreter runningstartup informationdisplayed>>> promptwaiting for input
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.

>>> 2 + 3 5 >>>

Following One Interaction

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

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

Evaluate: Python evaluates the arithmetic expression.

Print: Python displays the result 5 on the following line.

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

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.

processproducedisplaynext commandReadcommandEvaluateexpressionPrintresult>>> promptwait for input
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

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

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

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

  • Entering a command before Python is ready

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

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

  • Assuming the interaction ends after the result appears

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

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

Key Takeaways

  • 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.