Kuwepo kwa Kipengele Katika Tuple katika Python

Kujua ikiwa kipengele fulani kipo kwenye orodha inaweza kufanyika kwa kutumia kiendeshaji in:

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

print(res) # itatoa True

Ili kuangalia kutokuwepo kwa kipengele, inapaswa kutumika viendeshaji not in:

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

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

Imetolewa tuple:

pythontpl = (2, 4, 6, 10)

Angalia ikiwa nambari 8 ipo ndani yake.

Задание 2

Imetolewa tuple:

pythontpl = ('abc', 'def')

Angalia ikiwa kamba 'd' ipo ndani yake.

Задание 3

Imetolewa mifuatayo ya kodi:

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

print(res)

Sema, nini kitatolewa kwenye koni.

Задание 4

Imetolewa mifuatayo ya kodi:

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

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

Sema, nini kitatolewa kwenye koni.