Main Content


Create keyword arguments for Python function



kwa = pyargs(argKey,argValue) creates one or more keyword arguments to pass to a Python® function. A Python keyword argument is a value preceded by an identifier. Place pyargs as the final input argument to a Python function. For example:



collapse all

The Python complex function has keyword arguments real and imag. When you call this function in MATLAB®, use either the pyargs function or name=value syntax. Do not mix the two calling formats.

Call the function with a pyargs argument.

ans = 

  Python complex with properties:

    imag: 2
    real: 1


Alternatively, call the function with name=value syntax.


Input Arguments

collapse all

Python function keyword arguments specified as one or more comma-separated pairs of argKey,argValue arguments. argKey is the Python function key name and is a string or character vector. argValue is the argument value, represented by any valid Python type. Use the Python function argument list to identify argKey and argValue. You can specify several key and value pair arguments in any order as argKey1,argValue1,...,argKeyN,argValueN.

Example: 'length',int32(2)


  • Do not combine pyargs and name=value syntax when passing keyword arguments to Python functions.

  • MATLAB does not support name,value syntax for passing keyword arguments to Python functions. Use name=value syntax instead.

Alternative Functionality

You can pass Python keyword arguments using MATLAB name=value syntax. For more information, see Call Python complex Function Using Keyword Arguments.

Version History

Introduced in R2014b

expand all

Behavior changed in R2021b