mutt...@dastardlyhq.com wrote:
On Sat, 28 Jan 2023 14:22:01 +1300
dn <pythonl...@danceswithmice.info> wrote:
Do you know about the Python REPL?

Haven't learnt the acronyms yet.

REPL stands for "Read Evaluate Print Loop". It basically refers to the interactive interpreter, which reads input you type, evaluates it, prints the result, and loops (repeatedly does that).

An interesting point from your examples is that the output from the first two comes from different steps in that loop.

>>> eval("1+1")
2

Here, the E (evaluation) step runs eval("1+1"), which returns 2. The P (print) step then prints that result. If this was in a script, you wouldn't see any output, and the statement is pretty much useless - you'd need to assign the result to a variable or explicitly print it.

>>> eval("print(123)")
123

Here, the E step runs eval("print(123)"), which prints 123 and returns None. The P step doesn't print anything if the result is None. You'd still see that output if this was in a script.

Using eval in those examples is pretty pointless, since:
>>> 1+1
>>> print(123)
would produce the same results - but of course they were just simple examples.

--
Mark.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to