4

I recently worked on several projects and see a new syntax code, a method that get a * arguments(i know about *args and **kwargs)

for an example in django 2.0.4:

class DataListView(ListView):
    ...
    def get_context_data(self, *, object_list=None, **kwargs): # * argument without suffix
        return super().get_context_data(object_list, **kwargs)

and Question: what is meaning of * arguments in python function/method?

Hadi Farhadi
  • 1,773
  • 2
  • 16
  • 33

1 Answers1

3

It's so that object_list must be a named argument. All positional arguments will be captured by * and ignored.

This was added in python 3.0 and is described in PEP 3132 -- Extended Iterable Unpacking

Håken Lid
  • 22,318
  • 9
  • 52
  • 67