Tupel Vermenigvuldiging in Python
Ons kan ook tuplis vermenigvuldig, dit wil sê, 'n sekere aantal kere kopieer.
Dit word gedoen met behulp van die *-operator:
pythontpl = ('a', 'b')
res = tpl * 2
print(res) # sal ('a', 'b', 'a', 'b') uitdruk
Задание 1
Gegewe tupel:
pythontpl1 = ('1', '2', '3')
Skep die volgende tupel daaruit:
pythontpl2 = ('1', '2', '3', '1', '2', '3', '1', '2', '3')
Задание 2
Gegewe tuplis:
pythontpl1 = ('a', 'b')
tpl2 = (1, 2)
Skryf kode om die volgende tupel te kry:
pythontpl3 = ('a', 'b', 'a', 'b', 1, 2)