6.4.3 判断元素是否存在

更新于 2026年10月13日 版权声明
6.4.3 判断元素是否存在

# 1. 字符串
print('a' in 'abcd') # True
print('a' not in 'abcd') # False
# 2. 列表
list1 = ['a', 'b', 'c', 'd']
print('a' in list1) # True
print('a' not in list1) # False
# 3. 元组
t1 = ('a', 'b', 'c', 'd')
print('aa' in t1) # False
print('aa' not in t1) # True(https://www.daowen.com)

✍AI写作