在python中,要判断特定的值是否存在列表中,可使用关键字in,判断特定的值不存在列表中,可使用关键字not in

letters = ['A','B','C','D','E','F','G']
if 'A' in letters:
print('A'+' exists')
if 'h' not in letters:
print('h'+' not exists')

打印结果:

A exists
h not exists

一个稍微复杂的案例

定义2个列表分别为list_01跟list_02

list_01 = ['A','B','C','H']
list_02 = ['A','B','E','F']
 
通过判断查看list_01在list_02中的存在情况
list_01 = ['A','B','C','H']
list_02 = ['A','B','E','F'] for letter in list_01:
if letter in list_02:
print(letter+' is exists')
else:
print(letter+' is not exists')

打印结果:

A is exists
B is exists
C is not exists
H is not exists

 
 

最新文章

  1. 从客户端(txtContent="<p>1</p>")中检测到有潜在危险的 Request.Form 值
  2. springMVC配置(XML配置详解)
  3. EasyUI 后台管理系统
  4. 【pku2115-C Looooops】拓展欧几里得-不定方程
  5. 2016031901 - ubuntu15.1安装驱动
  6. X Window、GNOME和KDE之间的关系
  7. HTML5 调用手机相册和摄像头的方法并上传微信下测试通过
  8. Qt MinGW 使用联合编译IncrediBuild
  9. ubuntu12.10下arm-linux-gcc交叉编译环境的搭建
  10. 基于SUSE Linux做NFS文件挂载
  11. HDU 5306 Gorgeous Sequence
  12. Gradle 1.12用户指南翻译——第四十三章. 构建公告插件
  13. 关于Html5发展和应用前景
  14. GDI+_VB6_ARGB
  15. 事件冒泡的应用——jq on的实现
  16. 读书笔记(01) - JSON - JavaScript高级程序设计
  17. 解决MySQL5.6中的Slave延迟问题的基本教程
  18. 【QT】error: macro "SIGNAL" passed 3 arguments, but takes just 1
  19. STL标准库-Move对容器效率的影响
  20. klg-jpa:spring-data-jpa 最佳实践

热门文章

  1. hdu5985[概率dp] 2016青岛icpc现场赛
  2. HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
  3. NOIP2017赛前模拟10月30日总结
  4. codechef AUG17 T5 Chef And Fibonacci Array
  5. 用c#语言通过修改注册表改IE网页首页
  6. jsp和java获取文件或路径
  7. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---33
  8. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---23
  9. JavaScript变量提升和函数声明预解析
  10. window下Apache-http-server(httpd-2.4.12)安装与配置