Elemento buvimas tuple sąraše Python kalba
Sužinoti ar tam tikras elementas yra sąraše
galima naudojant operatorių in:
tpl = ('a', 'b' 'c')
res = 'a' in tpl
print(res) # išves True
Norint patikrinti elemento nebuvimą, reikia
naudoti operatorių not in:
tpl = ('a', 'b' 'c')
res = 'a' not in tpl
print(res) # išves False
Duotas tuple:
tpl = (2, 4, 6, 10)
Patikrinkite, ar jame yra skaičius 8.
Duotas tuple:
tpl = ('abc', 'def')
Patikrinkite, ar jame yra eilutė 'd'.
Duotas toks kodas:
tpl = ('1', '2', '3')
res = 1 not in tpl
print(res)
Pasakykite, kas bus išvesta į konsolę.
Duotas toks kodas:
tpl1 = ('ac', '3', 4, 'bd', 5)
tpl2 = (1, 2, 3)
res1 = 4 in tpl1
res2 = 2 not in tpl2
print(res1)
print(res2)
Pasakykite, kas bus išvesta į konsolę.