Functions

Positional-only Parameters

Use / to mark parameters that callers must pass by position.

Parameters before / are positional-only. value is the main input, while factor remains an ordinary parameter that can be named.

Source

def scale(value, /, factor=2, *, clamp=False):
    result = value * factor
    if clamp:
        result = min(result, 10)
    return result

print(scale(4))
print(scale(4, factor=3))

Output

8
12
def f(a, b, /, c, d): …positional onlypositional or kw
A bare `/` divides positional-only arguments from positional-or-keyword ones; callers cannot name `a` or `b`.

Parameters after * are keyword-only. That makes options such as clamp explicit at the call site.

Source

print(scale(4, clamp=True))

Output

8

Notes

See also

Run the complete example

Example code

Expected output

8
12
8

Execution time appears here after you run the example.