Edge Python
Esc

Go to

Commands

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

negative
zero
positive
Output

pass

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

done
Output

while

15
Output

while … else

The else runs when the loop ends without break.

loop finished cleanly
Output

for

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

a
b
c
Output
a 1
b 2
c 3
Output
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.

1
3
Output

for … else

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

done
Output

match / case

Supported patterns: literals (int, float, str and bytes with adjacent ones joined, negative numbers, and True, False and None, which match by identity so case True rejects 1), capture names, the _ wildcard, OR patterns with |, guards with if, as captures, and sequence patterns with an optional *rest, written [a, b], (a, b) or bare a, b. Parentheses without a comma only group, so (x) is the capture x.

Items in a sequence pattern are any of these patterns, nested sequences, OR groups and as captures included. A mapping pattern {"k": p, **rest} takes literal keys and matches only dicts. A class pattern Point(x, y=0) checks isinstance and reads positional attributes through __match_args__, while int(n) matches the subject itself. A dotted name such as Color.RED compares by value. 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.

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

try / except / else / finally

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.

parsed 42
cleanup
Output
caught
Output

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

subclass caught
Output

raise

rejected
Output

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

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.

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.

acquire
handle
release
after
Output

Multiple targets:

first second
Output
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.

released
10
released
negative
tick 0
tick 1
Output

assert

0.25
Output

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

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)).

gone
[1, 3]
Output