Python REPL
Photo by AltumCode on Unsplash
We are going to explore one of the most interesting feature of python: an interactive command line also known as REPL
What the *$! does REPL mean?
REPL acronym stands for
- Read (the computer reads what you typed and if it respects Python grammar rules transforms it into executable code)
- Eval (the python interpreter executes your code and get a result)
- Print (the python interpreter prints the result in a line below your text)
- Loop (Let’s start all over again)
Why should this interest me?
Instead of writing a program the REPL allows you to add a few commands at a time and immediately see the output
This allow you to get an immediate feedback and quickly explore various solutions with a “live” environment; you can build your calculations stepwise: I recommend to make experiments with this when possible as this will speed up your learning.
How do I use the Python REPL
Directly from your browser…
Or you can launch from a command line in your PC typing “python”
- Each command line starts with three > sign
- once the command is completed type enter and see the result
- multiline commands show a “…” prompt – this will allow you to break long commands in smaller pieces
But… then I lose all I wrote?
Short answer yes. But…
Actually there are many awesome extensions which allow you to:
- save your code and results
- see graphical outputs
- create documents including text and formulae in a lot of formats
- mixing results with other programming languages snippets
- easily execute operations on your PC
- share your work with others
- and much more
Just to name a few:
- IPython (I often use an extension called PTIPython)
- Jupyter Notebook (which executes many other programming languages too)
- Jupyter Lab (which does way more than execute code: remote terminals, file editing etc.)
- Jupyter Lite (which does the same things without any installation)