python - 检查列表是否包含除“apples”和“oranges”之外的其他字符串
问题描述
如何知道 python 中的列表是否包含除'apples'
and之外的其他元素'oranges'
。
fruits = ['apples', 'oranges']
现在,如果列表 fruits 包含任何其他字符串假设:
fruits = ['apples', 'oranges', grapes']
或者
fruits = ['oranges', grapes']
我该如何检查?
解决方案
试试下面的代码:
fruits = ['apples', 'oranges', 'grapes']
for i in fruits:
if i not in ['apples','oranges']:
print i # Mismatched values will be printed
输出:
grapes
推荐阅读
- mysql - BigQuery 和不在
- sql-server - 通过触发器或计划更新每个时间单位的累积数据
- python - Python & Plotly:通过字典自定义颜色到饼图
- python-3.x - Rasa 聊天机器人:检索对话数据
- jquery - 在 JQUERY 代码中使用两个 CSS 属性
- c++ - 克隆的 shared_ptr 和析构函数中的泄漏
- three.js - WebGL 着色器属性未准确传递
- python - 运行“文件名”时出错。系统找不到指定的文件(PyCharm)
- java - GraphQL 有没有办法在没有明确的“...on”查询的情况下获得解析的联合类型字段?
- itext7 - itext5 中的 PdfGraphics2D 类在 itext7 中的等效类是什么