Atskiras kortėžo elementas Python kalboje
Norint gauti kortėžo elementą, reikia kreiptis į jį pagal indeksą:
tpl = ('a', 'b', 'c')
print(tpl[0]) # išves 'a'
Duotas kortėžas:
tpl = (1, 2, 3, 4)
Išveskite iš jo pirmąjį elementą.
Duotas kortėžas:
tpl = ('a', 'b', 3, 4, 'c')
Išveskite iš jo trečiąjį elementą.
Duotas kortėžas:
tpl = (10, 9, 8, 7, 6)
Išveskite iš jo paskutinį elementą.
Iš kortėžo, nurodyto ankstesnėje užduotyje, išveskite priešpaskutinį elementą.
Duotas kortėžas:
tpl = (1, 2, 3)
Raskite šio kortėžo elementų sumą.