Prisotnost elementa v terki v Pythonu
Preveriti, ali element obstaja v seznamu,
lahko z operatorjem in:
tpl = ('a', 'b' 'c')
res = 'a' in tpl
print(res) # izpiše True
Za preverjanje odsotnosti elementa uporabite
operatorja not in:
tpl = ('a', 'b' 'c')
res = 'a' not in tpl
print(res) # izpiše False
Podana je terka:
tpl = (2, 4, 6, 10)
Preverite, ali vsebuje število 8.
Podana je terka:
tpl = ('abc', 'def')
Preverite, ali vsebuje niz 'd'.
Podana je naslednja koda:
tpl = ('1', '2', '3')
res = 1 not in tpl
print(res)
Povejte, kaj se bo izpisalo v konzolo.
Podana je naslednja koda:
tpl1 = ('ac', '3', 4, 'bd', 5)
tpl2 = (1, 2, 3)
res1 = 4 in tpl1
res2 = 2 not in tpl2
print(res1)
print(res2)
Povejte, kaj se bo izpisalo v konzolo.