Elementa esamība tuple Python

Var uzzināt, vai konkrētais elements atrodas sarakstā, izmantojot operatoru in:

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

print(res) # izvadīs True

Lai pārbaudītu elementa neesamību, jāizmanto operators not in:

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

print(res) # izvadīs False
Задание 1

Dots tuple:

pythontpl = (2, 4, 6, 10)

Pārbaudiet, vai tajā atrodas skaitlis 8.

Задание 2

Dots tuple:

pythontpl = ('abc', 'def')

Pārbaudiet, vai tajā atrodas virkne 'd'.

Задание 3

Dots šāds kods:

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

print(res)

Sakiet, kas tiks izvadīts konsolē.

Задание 4

Dots šāds kods:

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

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

Sakiet, kas tiks izvadīts konsolē.