Skip to content

Tuples

Tuples are immutable lists so it supports all the same operations similar to a list with the exception of modifications. Tuples are defined either using parantheses (with comma separation) or just as a comma separated list.

my_list = [1, 2]
my_tuple = (1, 2)
my_second_tuple = 1, 2
def add_multiply_function(x, y):
    return (x + y), (x * y)
results = add_multiply_function(2, 4)
print(results)
(6, 8)

add, multiply = add_multiply_function(3, 6)
print(add, multiply)
9 18

x, y = 10, 20
x, y = y, x
print(x, y)
20 10