The package registry is still being built. The docs are live, everything else is a preview.

Edge Python

Sign In

Sign in to publish packages and pin them by sha256.


By continuing, you accept our Terms and Conditions.

@
Palette

Control flow

if / elif / else

cmd + enter
negative
zero
positive
Output

pass

pass does nothing. Use it where the grammar requires a block.

cmd + enter
done
Output

while

cmd + enter
15
Output

while … else

The else runs when the loop ends without break.

cmd + enter
loop finished cleanly
Output

for

for iterates any iterable: list, tuple, dict, set, range, string, or generator.

cmd + enter
a
b
c
Output
cmd + enter
a 1
b 2
c 3
Output
cmd + enter
1 [2, 3]
4 [5, 6, 7]
Output

break and continue

break exits the loop. continue skips to the next item. Both work in for and while.

cmd + enter
1
3
Output

for … else

The else runs when the loop exhausts its iterator without break.

cmd + enter
done
Output

match / case

Supported patterns: literals (int, float, str, True, False, None, and negative numbers), capture names, the _ wildcard, OR patterns with |, guards with if, and sequence patterns with an optional *rest.

Items in a sequence pattern must be literals, capture names, or _. Nested sequence patterns, mapping patterns, class patterns, and as captures do not parse. Use chained if and elif for those. A sequence pattern matches only list and tuple subjects. Any other value, including str and bytes, fails the pattern and falls through to the next case.

cmd + enter
zero small negative other
Output
cmd + enter
empty
single 5
pair-equal
1 then 3 more
Output

try / except / else / finally

cmd + enter
5.0
None
Output

A handler names one exception, a tuple of exceptions, or nothing. A bare except catches everything. else runs when the try body raised nothing. finally always runs.

cmd + enter
parsed 42
cleanup
Output
cmd + enter
caught
Output

Handlers match subclasses. except Exception catches ValueError, RuntimeError, KeyError, and the rest of the hierarchy listed in Limits and errors.

cmd + enter
subclass caught
Output

raise

cmd + enter
rejected
Output

A bare raise inside an except block re-raises the exception being handled.

cmd + enter
logging
outer bad
Output

raise X from Y raises X. The from clause parses and Y evaluates, but the cause is not preserved. There is no __cause__ or __context__. Only X reaches the handler.

cmd + enter
caught the ValueError
Output

with

with runs the context manager protocol:

  1. Evaluate the expression.
  2. Call __enter__ and bind its result to the as target.
  3. On exit, call __exit__(exc_type, exc_value, traceback).

On a clean exit the three arguments are None. On an exception they carry the exception info. A truthy return from __exit__ suppresses the exception.

cmd + enter
acquire
handle
release
after
Output

Multiple targets:

cmd + enter
first second
Output
cmd + enter
suppressed
Output

Cleanup on early exit

finally and __exit__ run on every way out of a block. That includes normal completion, exceptions, return, break, and continue. A return or break inside finally replaces the original exit.

cmd + enter
released
10
released
negative
tick 0
tick 1
Output

assert

cmd + enter
0.25
Output

A failed assertion raises AssertionError. The message after the comma evaluates only on failure and becomes the exception argument (e.args).

cmd + enter
math broke
Output

del

del removes a binding. It works on plain names, attributes (del obj.attr), indexed positions (del seq[i]), and parenthesized groups (del (a, b)).

cmd + enter
gone
[1, 3]
Output