Skip to the workspace
Pebellslearn by building

Python syntax & reference

Find the form you need, compare how it behaves, and open the complete explanation when you need more depth.

Python 3.10+ syntax; individual entries identify newer features. Browser exercises use the configured Python runner.

3 matching syntax entries

Returning versus printing

Learn in depth →

return supplies a value to the caller. print sends text to an output stream.

def name(parameters):
    return expression

Example

def add_fee(subtotal):
    return subtotal + 20

bill = add_fee(100)
print(bill - 10)

Result

110

Watch for: Falling off the end returns None. A printed value cannot be used as the function result.

Practise this topic →

Argument forms

Learn in depth →

Parameters bind caller inputs; / and * restrict how arguments can be supplied.

def f(positional_only, /, normal, *, keyword_only): ...

Example

def quote(amount, /, tax=0, *, currency="INR"):
    return amount + tax, currency
print(quote(100, 18, currency="INR"))

Result

(118, 'INR')

Watch for: A default is evaluated when def executes. Use None and create a fresh container inside for a per-call mutable default.

Practise this topic →

Packing and unpacking

Learn in depth →

A tuple can carry several results. *args packs extra positional arguments and **kwargs packs keyword arguments.

a, b = pair
f(*values, **options)

Example

def summarize(*values, **options):
    return sum(values), options.get("unit", "items")
amount, unit = summarize(*[2, 3], unit="kg")
print(amount, unit)

Result

5 kg

Watch for: Unpacking must match the expected shape unless a starred target collects the remainder.

Practise this topic →
Complete explanation index (91 lessons indexed)

Functions

Technical sources and review date

Original Pebells examples. Reviewed 2026-10-28.

Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.