10.5. List Membership¶
in
and not in
are boolean operators that test membership in a sequence. We
used them previously with strings and they also work here.
1
fruit = ["apple", "orange", "banana", "cherry"]
2
3
print("apple" in fruit)
4
print("pear" in fruit)
5
(chp09_4)
Check your understanding
list-5-1: What is printed by the following statements?
alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False]
print(3.14 in alist)
list-5-2: What is printed by the following statements?
alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False]
print(57 in alist)