REPL
The ZPy REPL (Read-Eval-Print Loop) provides an interactive environment for experimenting with ZPy code.
Starting the REPL
bash
# Start REPL directly
zpy
# Or explicitly
zpy repl
# Or with -i flag
zpy -iREPL Features
Multi-line Input
The REPL automatically detects incomplete statements and continues on the next line:
>>> def greet(name):
... print("Hello,", name)
...
>>> greet("World")
Hello, WorldRun File Then REPL
Use -i to run a script and then enter the REPL:
bash
zpy -i script.zpyThis is useful for debugging - you can inspect variables after the script runs:
# script.zpy
x = 10
y = 20
$ zpy -i script.zpy
Script executed. Entering REPL...
>>> x
10
>>> y
20
>>> x + y
30REPL Commands
| Command | Description |
|---|---|
exit() | Exit the REPL |
Ctrl+C | Cancel current input |
Ctrl+D | Exit REPL (Unix) |
Tips
Quick Calculations
>>> 2 ** 10
1024
>>> 100 / 7
14.285714285714286Test Functions
>>> def factorial(n):
... if n <= 1:
... return 1
... return n * factorial(n - 1)
...
>>> factorial(5)
120
>>> factorial(10)
3628800Inspect Values
>>> items = [1, 2, 3, 4, 5]
>>> len(items)
5
>>> type(items)
list