Checking if an element is in a list in Python

To check if an element is in the list, we can use the in operator. In this case, if the element is present, we will get back the Boolean value True, otherwise - False:

pythonlst = [1, 2, 3]
res = 1 in lst

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

Given a list:

pythonlst = ['a', 'b', 'c', 'd', 'e']

Check for an element with value 'c'.

Задание 2

The following code is given:

pythonlst = ['a', 'b', 'c', 'd']
res = 'e' in lst

print(res)

Tell me what will be output to the console.

Задание 3

The following code is given:

pythonlst = ['a', 1, 'b', 3, 'c']
res = 3 in lst

print(res)

Tell me what will be output to the console.