Python REPL

altumcode-mCj7UinqOYQ-unsplash-scaled.jpg

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?

typecat.jpg

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…

print("get ready…♥") print(5,3,2,1,0,"rocket launch")

Or you can launch from a command line in your PC typing “python”

test5.gif

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

code_lost.jpg

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)

marco.p.v.vezzoli

Self taught assembler programming at 11 on my C64 (1983). Never stopped since then -- always looking up for curious things in the software development, data science and AI. Linux and FOSS user since 1994. MSc in physics in 1996. Working in large semiconductor companies since 1997 (STM, Micron) developing analytics and full stack web infrastructures, microservices, ML solutions

You may also like...