CKTIS / Python
tuple()
Erstellt aus einem iterierbaren Objekt ein unveränderliches geordnetes Tupel.
Version: Python 3.14; repository image, production runtime not attested
Syntax
tuple(iterable=(), /)Erstellt aus einem iterierbaren Objekt ein unveränderliches geordnetes Tupel.
Seine Plätze sind nicht neu belegbar, doch die Referenz führt zur selben Liste und das Anhängen von 2 ist sichtbar. Der Text ab liefert zwei Zeichen.
Ein exaktes tuple kann ohne Kopie zurückkommen.
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]
Beispiele
items = [1]
record = tuple([items])
items.append(2)
print(record)
print(tuple("ab"))
Ergebnis
([1, 2],)
('a', 'b')Ein exaktes tuple kann ohne Kopie zurückkommen.