Tuples

(Grundlegendes)

tup1 = ('Mechanik','Elektronik',1999,2021)
tup2 = (1, 2, 3, 4, 5)
tup3 = ("a", "b", "c", "d")

Zugriff auf Tuples

tup1[0]
'Mechanik'
tup1[3]
2021
tup1[2:4]
(1999, 2021)

Tuples aktualisieren nicht möglich

tup0 = ('Mechanik','Elektronik',1999,2021)
tup0[0] = 'Robotik'
tup0
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-2592b3b3eaaa> in <module>
      1 tup0 = ('Mechanik','Elektronik',1999,2021)
----> 2 tup0[0] = 'Robotik'
      3 tup0

TypeError: 'tuple' object does not support item assignment

Listenelemente löschen nicht möglich

tup0 = ('Mechanik','Elektronik',1999,2021)
del tup0[1]
tup0
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-59e8f136d956> in <module>
      1 tup0 = ('Mechanik','Elektronik',1999,2021)
----> 2 del tup0[1]
      3 tup0

TypeError: 'tuple' object doesn't support item deletion

Grundlegende Listenoperationen

len((1, 2, 3))
3
(1,2,3)+(4,5,6)
(1, 2, 3, 4, 5, 6)
("KI")*4
'KIKIKIKI'
1 in (1, 2, 3)
True
for x in (1, 2, 3): print(x)
1
2
3

Fortgeschrittene Techniken¶

Tipp

Für weitere Methoden sei auf Tupels im Abschnitt Fortgeschrittene verwiesen.