*args, **kwargs and keyword-only arguments in Python

Backend Live Coding November 13, 2026 python

Keyword-only arguments are useful in dangerous functions (money), to avoid mistakes with argument order.

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# ======================================================================
# Q: What are *args, **kwargs and keyword-only arguments?
#
# Keyword-only arguments are useful in dangerous functions (money), to avoid
# mistakes with argument order.
# ======================================================================

def create_order(customer, *items, notify=True, **meta):
    ...
create_order(c, item1, item2, notify=False, source='b2b')
# items = (item1, item2), meta = {'source': 'b2b'}

def transfer(src, dst, *, amount, reference):   # after the * only by name
    ...
transfer(a, b, amount=Decimal('10.00'), reference='TX-1')