Multiplikation af tupler i Python
Vi kan også gange tupler, dvs. kopiere
dem et bestemt antal gange. Det gøres
med operatoren *:
pythontpl = ('a', 'b')
res = tpl * 2
print(res) # vil udskrive ('a', 'b', 'a', 'b')
Задание 1
Givet en tuple:
pythontpl1 = ('1', '2', '3')
Opret følgende tuple fra den:
pythontpl2 = ('1', '2', '3', '1', '2', '3', '1', '2', '3')
Задание 2
Givne tupler:
pythontpl1 = ('a', 'b')
tpl2 = (1, 2)
Skriv kode for at opnå følgende tuple:
pythontpl3 = ('a', 'b', 'a', 'b', 1, 2)