Tilstedeværelse af element i tuple i Python

Man kan finde ud af om et givet element er på listen ved hjælp af operatoren in:

pythontpl = ('a', 'b' 'c')
res = 'a' in tpl

print(res) # vil udskrive True

For at kontrollere fraværet af et element, bør man bruge operatorerne not in:

pythontpl = ('a', 'b' 'c')
res = 'a' not in tpl

print(res) # vil udskrive False
Задание 1

Givet en tuple:

pythontpl = (2, 4, 6, 10)

Kontroller, om tallet 8 er i den.

Задание 2

Givet en tuple:

pythontpl = ('abc', 'def')

Kontroller, om strengen 'd' er i den.

Задание 3

Givet følgende kode:

pythontpl = ('1', '2', '3')
res = 1 not in tpl

print(res)

Sig, hvad der udskrives i konsollen.

Задание 4

Givet følgende kode:

pythontpl1 = ('ac', '3', 4, 'bd', 5)
tpl2 = (1, 2, 3)

res1 = 4 in tpl1
res2 = 2 not in tpl2
print(res1)
print(res2)

Sig, hvad der udskrives i konsollen.