0

Hi i have several lines of python code, which confuses me:

def apply_async(func, args,*, callback):
    # Compute the result
    result = func(*args)
    # Invoke the callback with the result
    callback(result)

def print_result(result):
    print('Got:', result)

def add(x, y):
    return x + y

apply_async(add, (2, 3), callback=print_result)

I understand that to write a function that accepts any number of positional arguments, use a * argument.

But i couldn't understand why * appear ater args. and then *args can represent the tuple (2,3) in this example?

jake y
  • 15
  • 3

1 Answers1

1

This is https://www.python.org/dev/peps/pep-3102. All arguments after the * must be named arguments.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173