Python Data Types and Expressions
Start the Python interpreter by typing 'python' in a terminal; Python will display version information and a >>> prompt.
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.
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.
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
>>>- 1At the first prompt, enter 2 + 3 and press Enter.
- 2Python evaluates the mathematical expression.
- 3Python prints the result 5.
- 4Python 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.
5Following One Interaction
What happens when the command 2 + 3 is entered at the >>> prompt?
- 1Enter
The learner types 2 + 3 at the visible >>> prompt and presses Enter.
- 2Evaluate
Python evaluates the arithmetic expression.
- 3Print
Python displays the result 5 on the following line.
- 4Wait
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.
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 + 3Why it failsThe >>> characters are Python's displayed prompt, not part of the command you should enter.
Do this insteadEnter only 2 + 3 when the >>> prompt is visible.
Common mistake Entering a command before Python is ready
What it looks likeTyping while startup information is still being displayed
Why it failsThe visible >>> prompt is the signal that Python is ready to receive input.
Do this insteadWait until >>> appears before entering the next command.
Common mistake Assuming the interaction ends after the result appears
What it looks likeStopping after seeing 5
Why it failsInteractive mode displays a new prompt after evaluation so that you can continue the conversation.
Do this insteadLook for the new >>> prompt and use it to enter another command.
Prompt Practice
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.
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
- 1Type python in a terminal and press Enter to start the Python interpreter in interactive mode.
- 2Python displays version information and then shows the >>> prompt when it is ready for a command.
- 3Type only your command; the >>> prompt is displayed by Python.
- 4After a command is entered, Python reads it, evaluates it, prints the result, and displays a new >>> prompt.
- 5The 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.