0Pricing
Python Academy · Lesson

args and kwargs

Accept variable-length positional and keyword arguments.

Introduction

*args and **kwargs let functions accept variable numbers of positional and keyword arguments.

What is *args?

def f(*args) collects all extra positional arguments into a tuple named args.
def f(*args):
    print(args)
f(1, 2, 3)  # (1, 2, 3)

All lessons in this course

  1. Defining and Calling Functions
  2. Default and Keyword Arguments
  3. args and kwargs
  4. Return Values and Scope
← Back to Python Academy