Provera prisustva elementa u tuple u Pythonu
Možemo saznati da li određeni element postoji u listi
koristeći operator in:
tpl = ('a', 'b' 'c')
res = 'a' in tpl
print(res) # ispisaće True
Da biste proverili odsustvo elementa, treba da
koristite operatore not in:
tpl = ('a', 'b' 'c')
res = 'a' not in tpl
print(res) # ispisaće False
Dat je tuple:
tpl = (2, 4, 6, 10)
Proverite da li u njemu postoji broj 8.
Dat je tuple:
tpl = ('abc', 'def')
Proverite da li u njemu postoji string 'd'.
Dat je sledeći kod:
tpl = ('1', '2', '3')
res = 1 not in tpl
print(res)
Recite šta će biti ispisano u konzolu.
Dat je sledeći kod:
tpl1 = ('ac', '3', 4, 'bd', 5)
tpl2 = (1, 2, 3)
res1 = 4 in tpl1
res2 = 2 not in tpl2
print(res1)
print(res2)
Recite šta će biti ispisano u konzolu.