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