Press "Enter" to skip to content

The difference between python3 function passing parameters * and **

positional argument
keyword argument

The difference between *args and **kwargs, both are variadic arguments in python:

*args represents any number of unnamed arguments, which is essentially a tuple

**kwargs means keyword arguments, which is essentially a dict

When using both *args and **kwargs, the *args argument must be listed before **kwargs.


Source: Python Crash Course, 2nd Edition A Hands-On:

Note: You’ll often see the generic parameter name *args, which collects arbitrary positional
arguments like this.

Note: You’ll often see the parameter name **kwargs used to collect non-specific keyword
arguments.

Be First to Comment

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注