Code

Any Number of Things

Sometimes you don't know how many arguments are coming. A star collects them for you.

*args, extra positional arguments

def shout_all(*words):
    for w in words:          # words is a tuple
        print(w.upper())

shout_all("hi", "yo", "hey")

**kwargs, extra keyword arguments

def show(**info):            # info is a dict
    for key, value in info.items():
        print(key, "=", value)

show(hp=10, gold=3)

The names args and kwargs are just a convention, what matters is the * and **. You've already used a function like this: print accepts any number of values!

Assignment

  1. total_loot(*coins) returns the sum of all the numbers passed in (and 0 if none are passed). Use a loop.
  2. make_badge(name, **traits) returns the name followed by each trait as key=value, joined by ", ", inside brackets: make_badge("Pip", role="guide", level=3) gives "Pip (role=guide, level=3)". With no traits it returns just "Pip".