Not every Pythonista knows of the lone star.

Say you want some keyword arguments that have to be mentioned, but you
would never allow them to be reached positionally.

Or: it's fine if you don't mention them, but if you know they exist, you
have powers.

def game_boot_up(pos0, pos1, *, cheat = False):  # define a function

Now you can start it with:

>>> game_boot_up(1, 2)  # ignore the keyword parameter (it has a default)

and all will be fine.  You can't try to probe with an extra positional
"just in case":

>>> game_boot_up(1, 2, True)  # anything?  -- raises exception

But if you know the secret key by name...

>>> game_boot_up(1, 2, cheat = True)

Caveat:  Python tends to blab what the "secret param" is in the Traceback
so this isn't really how to embed a secret cheat.

The point is to understand the role of the lone star better, a relatively
obscure corner of the language.

If the params after the lone star don't have default values then the
corresponding keyword arguments will be required.

Keyword are arguments required and yet are not pre-committed to any
defaults.  Useful.

Kirby
_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
https://mail.python.org/mailman/listinfo/edu-sig

Reply via email to