25

What does a single * without identifier mean in the Python function arguments? Here is an example that works with Python3.2:

class Shape:
    def __init__(self, *, shapename, **kwds):
        self.shapename = shapename
        super().__init__(**kwds)

For me the star after the self is strange.

I have found it here (from row 46): http://code.activestate.com/recipes/577720-how-to-use-super-effectively/

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
  • 1
    Extra points for the one who points to the PEP ;) (i remember reading a fragment a PEP describing this, but i can't remember where, or what it was, **/me goes back to google**) – KurzedMetal Jul 06 '12 at 16:14

1 Answers1

22

The lone * indicates that all following arguments are keyword-only arguments, that is, they can only be provided using their name, not as positional argument.

See PEP 3102 for further details.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
  • 2
    In other words: `shapename` has to be explicitly added when creating a new `Shape` object, like `Shape(shapename='Circle')` – KurzedMetal Jul 06 '12 at 16:22