Search code examples
pythonprogramming-languages

Is Python multiple arguments return syntax sugar?


There isn't a straight answer on web, so I thought I'll ask here.

When a Python function returns multiple values is this just a syntax sugar for returning a list of elements that gets destructured after it's returned?


Solution

  • It's equivalent to returning a tuple, not a list.

    The tuple may or may not get destructed depending on what the caller does with it. If the caller keeps a reference to the tuple, it will continue to exist for as long as there are references to it.