CKTIS / Python
tuple()
Collects successive values into an immutable ordered sequence.
Version: Python 3.14; repository image, production runtime not attested
Syntax
tuple(iterable=(), /)Collects successive values into an immutable ordered sequence.
An outer tuple prevents replacing its elements but does not freeze mutable objects stored inside it.
A tuple keeps element order and forbids rebinding a position. The example stores a reference to the original list, so appending 2 to it becomes visible in the tuple. A string contributes its characters. Passing an exact built-in tuple can return that same object, and no argument yields ().
x = (1, 2)
assert tuple(x) is x and tuple("ab") == ("a", "b")
v = []
t = tuple([v])
v.append(1)
assert t[0] is v and t[0] == [1]
Examples
items = [1]
record = tuple([items])
items.append(2)
print(record)
print(tuple("ab"))
Result
([1, 2],)
('a', 'b')A tuple keeps element order and forbids rebinding a position. The example stores a reference to the original list, so appending 2 to it becomes visible in the tuple. A string contributes its characters. Passing an exact built-in tuple can return that same object, and no argument yields ().