Elementin läsnäolo tuple:ssa Pythonissa
Voit selvittää onko tietty elementti listassa
käyttämällä in-operaattoria:
pythontpl = ('a', 'b' 'c')
res = 'a' in tpl
print(res) # tulostaa True
Jotta voit tarkistaa elementin puuttumisen, sinun tulisi
käyttää not in-operaattoria:
pythontpl = ('a', 'b' 'c')
res = 'a' not in tpl
print(res) # tulostaa False
Задание 1
Annettu tuple:
pythontpl = (2, 4, 6, 10)
Tarkista, onko siinä luku 8.
Задание 2
Annettu tuple:
pythontpl = ('abc', 'def')
Tarkista, onko siinä merkkijono 'd'.
Задание 3
Annettu seuraava koodi:
pythontpl = ('1', '2', '3')
res = 1 not in tpl
print(res)
Mitä konsoliin tulostuu?
Задание 4
Annettu seuraava koodi:
pythontpl1 = ('ac', '3', 4, 'bd', 5)
tpl2 = (1, 2, 3)
res1 = 4 in tpl1
res2 = 2 not in tpl2
print(res1)
print(res2)
Mitä konsoliin tulostuu?