poros
10/5/2015 - 11:20 PM

Keyword-only arguments

Keyword-only arguments

def func(arg1, arg2, arg3=10, arg4=0):
  ...
  
# problem
func(1, 2, 10, 0)
# or ?
func(1, 2, 0, 10)

# PYTHON 3 ONLY
def func(arg1, arg2, *, arg3=10, arg4=0):
  ...

func(1, 2, 10, 0)  # ERROR
func(1, 2, arg3=10, arg4=0)

# also
def func(arg1, *args, optional_arg=None):
  ...


# PYTHON 2: fun(arg1, arg2, *args, **kwargs) is similar