Python成员运算符

除了以上的一些运算符之外,Python还支持成员运算符,测试实例中包含了一系列的成员,包括字符串,列表或元组。

运算符 描述 实例
in 如果在指定的序列中找到值返回 True,否则返回 False。 x 在 y 序列中 , 如果 x 在 y 序列中返回 True。
not in 如果在指定的序列中没有找到值返回 True,否则返回 False。 x 不在 y 序列中 , 如果 x 不在 y 序列中返回 True。

以下实例演示了Python所有成员运算符的操作:

实例(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- a = 10 b = 20 list = [1, 2, 3, 4, 5 ]; if ( a in list ): print "1 - 变量 a 在给定的列表中 list 中" else: print "1 - 变量 a 不在给定的列表中 list 中" if ( b not in list ): print "2 - 变量 b 不在给定的列表中 list 中" else: print "2 - 变量 b 在给定的列表中 list 中" # 修改变量 a 的值 a = 2 if ( a in list ): print "3 - 变量 a 在给定的列表中 list 中" else: print "3 - 变量 a 不在给定的列表中 list 中"

以上实例输出结果:

1 - 变量 a 不在给定的列表中 list 中
2 - 变量 b 不在给定的列表中 list 中
3 - 变量 a 在给定的列表中 list 中

最新文章

  1. Express 教程 01 - 入门教程之经典的Hello World
  2. EF深入系列--细节
  3. Java_过滤字符串中非汉子的内容
  4. Linux(centos)系统各个目录的作用详解
  5. [Whole Web, Nods.js, PM2] Passing environment variables to node.js using pm2
  6. oauth2认证
  7. redis requires Ruby version >= 2.2.2问题
  8. CXF2.7整合spring发布webservice
  9. toolbar按钮添加图标
  10. Java 1.ExecutorService四种线程池的例子与说明
  11. 安装SQL2008时显示:RebootRequiredCheck 检查是否需要挂起计算机重新启动。
  12. Spring点滴六:Spring中定义bean的继承
  13. C#细说多线程(上)
  14. jQuery中的find()与filter()
  15. lvs+keepalived+vsftp配置FTP服务器负载均衡
  16. JS this的指向
  17. 兼容获取元素当前样式 currentStyle || getComputedStyle
  18. elk,centos7,filebeat,elasticsearch-head详细安装步骤
  19. 转载-ActiveMQ通过JAAS实现的安全机制
  20. python 函数调用

热门文章

  1. Cesium模型贴地问题(八)
  2. Loadrunner性能测试简记
  3. Moonraker
  4. 用于双目重建中的GPU编程:julia-cuda
  5. CSS 定位position
  6. 自己动手从零写桌面操作系统GrapeOS系列教程——7.计算机组成与运行原理
  7. 基于TDSQL-C对OOM问题进行优化
  8. linux ubuntu 连接mysql
  9. 1487. 保证文件名唯一 (Medium)
  10. 使用svg让页面自适应浏览器大小,整体等比缩放