python 入门语法复习(四)

列表条件测试

形式如下:
if ‘element’ in list : ———–如果元素’element’在list列表中
if ‘element’ not in list : ——如果元素’element’不在list列表中

example:


classes = ['math', 'Chinese', 'English', 'physics', 'history']
res = 'math' in classes
print(res)

# 检查特定值是否包含在列表中
if 'math' in classes:
    print('beautiful!')

ans = 'IT' in classes
print(ans)

# 检查特定值是否 不在列表中
if 'IT' not in classes:
    print('error...')

猜你喜欢

转载自blog.csdn.net/weixin_43469047/article/details/89712086