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

Functions

Functions are values. Pass them, return them, store them, compose them.

def

cmd + enter
7
Output

Default arguments

cmd + enter
Hello, world!
Hi, world!
Output

Keyword arguments

cmd + enter
123
123
123
Output

Variadic parameters

*args collects extra positional arguments into a tuple. **kwargs collects extra keyword arguments into a dict.

cmd + enter
6
60
Output
cmd + enter
[('host', 'api'), ('port', 443)]
Output

Keyword-only parameters

A bare * marks the following parameters as keyword-only. They must be passed by name. A positional argument that would reach them raises TypeError, as does any positional argument beyond the declared parameters when there is no *args.

cmd + enter
api:80 secure=False
api:443 secure=True
rejected
Output

Argument unpacking at the call site

cmd + enter
6
6
6
6
Output

lambda

An anonymous function. The body is a single expression.

cmd + enter
42
7
Hi, world
Output

First-class functions

Store functions in data structures and pass them as arguments.

cmd + enter
[3, '-0x3', '-3']
Output
cmd + enter
7
12
4
Output

Function attributes

Functions carry writable attributes, like any object. getattr / hasattr / setattr / delattr work on them, and an assigned __name__ wins over the declared one. Decorators use these for metadata.

cmd + enter
10
n/a
True
Output

Higher-order functions

Functions that take or return functions.

cmd + enter
25
10
Output
cmd + enter
8
13
Output

Closures

An inner function captures the variables of its enclosing scope by reference.

cmd + enter
1
2
3
Output

Because capture is by reference, every lambda in a loop sees the same loop variable. Bind the current value through a default argument.

cmd + enter
10 11 12
Output

global and nonlocal

Assignment inside a function creates a local unless declared otherwise. nonlocal name rebinds the nearest enclosing function’s variable. That is the shared cell the counter closure above relies on. global name rebinds the module-level variable.

cmd + enter
7
Output

Reading an outer variable needs no declaration. Only rebinding does.

cmd + enter
15
Output

Recursion

cmd + enter
3628800
Output
cmd + enter
True False
Output

Pure functions are memoized after two calls with the same arguments. The VM detects purity statically (no I/O, no mutation, no raise, no yield) and confirms it at runtime. Any call that performs a side effect, including a builtin like print passed as a first-class value, marks the call impure and skips the cache, so memoization never drops an effect. Naive recursion runs at memoized cost with no source changes. See Design for the full model.

Generators

A function containing yield produces its sequence lazily. Pull values with next() or iterate with for.

cmd + enter
0
1
4
9
16
Output
cmd + enter
1
2
Output
cmd + enter
[1, 2, 3, 4, 5]
Output

yield from

Delegate to another generator or any iterable.

cmd + enter
[0, 1, 2, 10, 20]
Output

yield from is also an expression. It evaluates to the subgenerator’s return value, so a generator can pass a result back to its delegating caller.

cmd + enter
returned done
[1, 2]
Output

Generators are one-way producers. gen.send(value), gen.throw(exc), and gen.close() are not exposed. For bidirectional flow, use the cooperative scheduler and pass values through arguments and return values.

Generator expressions

A generator inline.

cmd + enter
30
5
Output

Decorators

A decorator wraps another callable. It applies to both functions and classes (see Classes).

cmd + enter
calling with (3, 4)
7
Output

Stacked decorators apply bottom-up.

cmd + enter
12
Output

A parameterized decorator is a factory. The outer function takes the decorator arguments and returns the actual decorator. The wrapped function captures both scopes.

cmd + enter
hi world
hi world
hi world
Output