Přítomnost prvku v n-tiici v Pythonu
Zjistit, zda je daný prvek v seznamu
lze pomocí operátoru in:
tpl = ('a', 'b' 'c')
res = 'a' in tpl
print(res) # vypíše True
Pro ověření nepřítomnosti prvku by se měly
použít operátory not in:
tpl = ('a', 'b' 'c')
res = 'a' not in tpl
print(res) # vypíše False
Daná n-tice:
tpl = (2, 4, 6, 10)
Zkontrolujte, zda obsahuje číslo 8.
Daná n-tice:
tpl = ('abc', 'def')
Zkontrolujte, zda obsahuje řetězec 'd'.
Daný následující kód:
tpl = ('1', '2', '3')
res = 1 not in tpl
print(res)
Řekněte, co se vypíše do konzole.
Daný následující kód:
tpl1 = ('ac', '3', 4, 'bd', 5)
tpl2 = (1, 2, 3)
res1 = 4 in tpl1
res2 = 2 not in tpl2
print(res1)
print(res2)
Řekněte, co se vypíše do konzole.