Your Python® documentation shows you how to call a Python function. Python function signatures look similar to MATLAB® function signatures. However, Python has syntax which might be unfamiliar to MATLAB users.
A positional argument is passed by position. These arguments appear at the beginning of a function signature.
Python Signature | MATLAB Usage |
---|---|
| py.abs(-99) |
Some functions accept an arbitrary sequence of positional arguments,
including no arguments. In Python, these arguments are defined
by prepending the name with the *
character.
Python Signature | MATLAB Usage |
---|---|
| Aggregate elements from two lists. Create
zero length
iterator. |
A keyword argument is preceded by an identifier. Keyword arguments, also called named arguments, can be specified in any order.
Keyword arguments are like name-value pairs in MATLAB.
Use the MATLAB pyargs
function to create
keyword arguments for Python functions.
Python Signature | MATLAB Usage |
---|---|
| Change the value of
|
Python defines an arbitrary number of keyword arguments
by prepending the name with **
characters.
Python Signature | MATLAB Usage |
---|---|
| D = py.dict(pyargs('Joe',100,'Jack',101)) |
An optional argument is a non-required argument.
Python Signature | MATLAB Usage |
---|---|
| py.random.randrange(1,100) |
Optional arguments can have default values. A default value
is indicated by an equal sign =
with the default
value.
Python Signature | MATLAB Usage |
---|---|
| Print two values using default keyword
values. |