We can use Python in
operator to check if a string is present in the list or not. There is also a not in
operator to check if a string is not present in the list.
我们可以使用Python in
运算符来检查列表中是否存在字符串。 还有一个not in
运算符,用于检查列表中是否不存在字符串。
l1 = ['A', 'B', 'C', 'D', 'A', 'A', 'C']
# string in the list
if 'A' in l1:
print('A is present in the list')
# string not in the list
if 'X' not in l1:
print('X is not present in the list')
Output:
输出:
A is pr