Using an interactive shell (REPL)

Python:
Using an interactive shell (REPL)

How to:

Jump right into Python’s REPL by typing python in your command line. Once there, test out simple operations or multi-line code:

>>> 1 + 1
2
>>> for i in range(3):
...     print(i)
... 
0
1
2

Experiment with functions and immediate feedback:

>>> def greet(name):
...     return "Hello, " + name + "!"
... 
>>> greet("Alice")
'Hello, Alice!'

Play with libraries and explore their features in real-time:

>>> import math
>>> math.sqrt(16)
4.0

Exit with a quick exit() or Ctrl+D (sometimes Ctrl+Z on Windows).

Deep Dive

The concept of a REPL is not unique to Python; it’s as old as Lisp. Many languages offer this immediate, interactive environment for a hands-on approach to code. Alternatives to the native Python shell include IPython and Jupyter Notebook, which provide enhanced interactivity, more features, and better integration with other tools. Python’s standard REPL is simple, but it embeds the full power of Python, handling complex objects and multi-threaded programs, though it lacks features like auto-completion and syntax highlighting present in more advanced tools.

See Also