Content · Programming · Python

Python Evaluate Expressions in the Interactive Shell

The interactive shell is useful for testing expressions because it immediately displays the value they produce. Learn the essential ideas and try a practical example.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

The interactive shell is useful for testing expressions because it immediately displays the value they produce.

Understanding the Concept


Expressions such as 10 / 4, 2 ** 5, and "Hello".upper() can be entered at the >>> prompt. The REPL evaluates each expression and displays its representation. Assignments usually do not display a value automatically; use the name on another line to inspect it. This makes the shell a good place to verify an operator or function before adding it to a longer script.

When and Why You Would Use This


Use the transcript below to see how successive expressions relate. Type only the text after each prompt. Your version banner and other environment details may differ.

Practical Example


>>> rectangle_width = 4
>>> rectangle_height = 3
>>> rectangle_width * rectangle_height
12
>>> rectangle_width + rectangle_height
7

Understanding the Example


The first two lines bind names but produce no displayed result. The arithmetic expressions then evaluate to 12 and 7. The displayed values do not automatically become new variables.

Try It Yourself


Use the shell to test 13 // 4 and 13 % 4. Predict each result and then verify.

Common Beginner Mistakes


  • Pasting >>> prompt characters into a .py file.
  • Assuming an assignment prints its value automatically in the REPL.
  • Forgetting that interactive variables vanish after the interpreter session ends.

Key Takeaways


  • REPL is ideal for quick expression experiments.
  • Expressions display results automatically in interactive mode.
  • Assignments establish names for subsequent expressions.
Share this resourceSend this page to someone who may find it useful.