Last modified: Jan 27, 2026 By Alexander Williams

Python Return Tuple Guide: Functions & Unpacking

Returning a tuple from a function is a core Python skill. It lets you send back multiple values. This guide explains how and why to do it.

What is a Tuple in Python?

A tuple is an ordered, immutable collection. It is defined with parentheses. Items are separated by commas.

Its immutability makes it a safe choice for fixed data. For a deeper dive, see our guide on Python Tuples: Immutable Data Structures Explained.

Why Return a Tuple from a Function?

Functions typically return one object. Using a tuple, you can return several. This is cleaner than using global variables.

It is common for calculations that produce related results. Think of coordinates, statistics, or status codes with messages.

Basic Syntax for Returning a Tuple

You create a tuple directly in the return statement. Use parentheses. The comma is what defines the tuple.


def get_coordinates():
    """Returns x and y coordinates as a tuple."""
    x = 10
    y = 20
    return (x, y)  # The parentheses make a tuple

# Call the function
result = get_coordinates()
print(result)
print(type(result))
    

(10, 20)
<class 'tuple'>
    

Implicit Tuple Creation in Return

Python is smart. You can omit the parentheses. Separating values with a comma is enough.


def get_user_info():
    name = "Alice"
    age = 30
    return name, age  # This implicitly creates a tuple

info = get_user_info()
print(info)
    

('Alice', 30)
    

Unpacking Returned Tuples

This is the most powerful feature. You can assign the tuple's items directly to separate variables.


def calculate_stats(numbers):
    total = sum(numbers)
    count = len(numbers)
    average = total / count
    return total, count, average  # Returns a 3-item tuple

# Unpack the returned tuple into three variables
sum_val, num_count, avg_val = calculate_stats([1, 2, 3, 4, 5])
print(f"Sum: {sum_val}, Count: {num_count}, Average: {avg_val}")
    

Sum: 15, Count: 5, Average: 3.0
    

This technique makes code very readable. Learn more in our Python Tuple Packing and Unpacking Guide.

Using the Underscore for Unwanted Values

Sometimes you don't need all returned values. Use an underscore _ as a placeholder.


def get_file_metadata():
    filename = "report.pdf"
    size = 2048
    created = "2023-10-01"
    return filename, size, created

# We only need the filename and creation date
name, _, date = get_file_metadata()
print(f"File: {name}, Created: {date}")
    

File: report.pdf, Created: 2023-10-01
    

Returning Tuples of Different Data Types

Tuples can mix types. This is useful for status messages or configuration settings.


def process_data(data):
    if not data:
        # Return a success flag (bool) and a message (str)
        return False, "Error: No data provided"
    # Process data...
    return True, "Processing complete"

success, message = process_data([])
print(f"Success: {success}")
print(f"Message: {message}")
    

Success: False
Message: Error: No data provided
    

Tuple vs List for Function Returns

Why use a tuple and not a list? The key is intent.

A tuple signals that the data is fixed and should not change. A list suggests a mutable collection you might modify.

Tuples are also slightly faster for iteration. For a full comparison, read Python Tuple vs List: Key Differences Explained.

Common Use Cases and Examples

Returning tuples is everywhere in Python. Here are practical examples.

1. Multiple Mathematical Results


def min_max(values):
    """Return the minimum and maximum value from a sequence."""
    return min(values), max(values)

low, high = min_max([5, 2, 9, 1, 7])
print(f"Min: {low}, Max: {high}")
    

Min: 1, Max: 9
    

2. Returning a Success/Failure State


def divide(a, b):
    try:
        result = a / b
        return True, result  # Success, result
    except ZeroDivisionError:
        return False, "Cannot divide by zero"  # Failure, message

status, value = divide(10, 2)
print(status, value)
status, value = divide(10, 0)
print(status, value)
    

True 5.0
False Cannot divide by zero
    

Best Practices for Returning Tuples

Follow these tips for clean code.

Keep it small. Return 2-3 values max. More can be confusing. Consider a dictionary or a dataclass for complex data.

Use descriptive variable names when unpacking. It documents what each value is.

Be consistent. If a function returns a tuple, always return the same number of items in the same order.

For more on working with tuples after you get them, see Python Tuple Operations and Concatenation Guide.

Conclusion

Returning tuples is a simple yet powerful Python pattern. It allows functions to output multiple related values cleanly.

Remember to use tuple unpacking for readability. Choose tuples over lists when your data is fixed. This makes your code's intent clear.

Start using this technique in your functions today. It will make your code more expressive and efficient.