Konverzia na n-ticu v Pythone
Funkcia tuple umožňuje nielen
vytvárať n-tice, ale aj konvertovať na
ne rôzne objekty, napríklad reťazce,
zoznamy.
Vytvorme n-ticu z reťazca:
txt = 'abcde'
tpl = tuple(txt)
print(tpl) # vypíše ('a', 'b', 'c', 'd', 'e')
Daná premenná:
tst = ['a', 'b', 'c', 'd']
Preveďte obsah premennej na n-ticu.
Daná premenná:
tst = 'abcde'
Preveďte obsah premennej na n-ticu.
Daná premenná:
tst = 12345
Preveďte obsah premennej na n-ticu.