在Python中使用成员运算符的示例


Posted in Python onMay 13, 2015

下表列出了所有Python语言支持的成员运算符。

在Python中使用成员运算符的示例

 例如:

试试下面的例子就明白了所有的Python编程语言提供会员运算符:

#!/usr/bin/python

a = 10
b = 20
list = [1, 2, 3, 4, 5 ];

if ( a in list ):
  print "Line 1 - a is available in the given list"
else:
  print "Line 1 - a is not available in the given list"

if ( b not in list ):
  print "Line 2 - b is not available in the given list"
else:
  print "Line 2 - b is available in the given list"

a = 2
if ( a in list ):
  print "Line 3 - a is available in the given list"
else:
  print "Line 3 - a is not available in the given list"

当执行上面的程序它会产生以下结果:

Line 1 - a is not available in the given list
Line 2 - b is not available in the given list
Line 3 - a is available in the given list
Python 相关文章推荐
Python内置函数dir详解
Apr 14 Python
python使用WMI检测windows系统信息、硬盘信息、网卡信息的方法
May 15 Python
java中的控制结构(if,循环)详解
Jun 26 Python
Python (Win)readline和tab补全的安装方法
Aug 27 Python
python 用户交互输入input的4种用法详解
Sep 24 Python
python hashlib加密实现代码
Oct 17 Python
Python常用模块os.path之文件及路径操作方法
Dec 03 Python
重写django的model下的objects模型管理器方式
May 15 Python
如何把python项目部署到linux服务器
Aug 26 Python
python3中for循环踩过的坑记录
Dec 14 Python
python获取淘宝服务器时间的代码示例
Apr 22 Python
Pandas数据类型之category的用法
Jun 28 Python
总结Python中逻辑运算符的使用
May 13 #Python
解析Python中的二进制位运算符
May 13 #Python
整理Python中的赋值运算符
May 13 #Python
实例说明Python中比较运算符的使用
May 13 #Python
举例讲解Python中的算数运算符的用法
May 13 #Python
详细解析Python中的变量的数据类型
May 13 #Python
Python编程入门的一些基本知识
May 13 #Python
You might like
PHP SEO优化之URL优化方法
2011/04/21 PHP
php使用CURL不依赖COOKIEJAR获取COOKIE的方法
2015/06/17 PHP
PHP的PDO常用类库实例分析
2016/04/07 PHP
浅析php静态方法与非静态方法的用法区别
2016/05/17 PHP
php单元测试phpunit入门实例教程
2017/11/17 PHP
PHP生成随机码的思路与方法实例探索
2019/04/11 PHP
laravel框架创建授权策略实例分析
2019/11/22 PHP
DB.ASP 用Javascript写ASP很灵活很好用很easy
2011/07/31 Javascript
使用jsonp完美解决跨域问题
2014/11/27 Javascript
AngularJS 自定义过滤器详解及实例代码
2016/09/14 Javascript
通过网页查看JS源码中汉字显示乱码的解决方法
2016/10/26 Javascript
Vuex之理解state的用法实例
2017/04/19 Javascript
vue轮播图插件vue-awesome-swiper的使用代码实例
2017/07/10 Javascript
Vue多系统切换实现方案
2018/06/05 Javascript
NodeJs操作MongoDB教程之分页功能以及常见问题
2019/04/09 NodeJs
layui表格内容溢出的解决方法
2019/09/06 Javascript
Node.js API详解之 Error模块用法实例分析
2020/05/14 Javascript
Python实现配置文件备份的方法
2015/07/30 Python
Python AES加密模块用法分析
2017/05/22 Python
python批量查询、汉字去重处理CSV文件
2018/05/31 Python
python 3.6.5 安装配置方法图文教程
2018/09/18 Python
利用python实现平稳时间序列的建模方式
2020/06/03 Python
keras的load_model实现加载含有参数的自定义模型
2020/06/22 Python
python MD5加密的示例
2020/10/19 Python
英国领先的狗和宠物美容专家:Christies Direct
2017/04/03 全球购物
运动鞋中的劳斯莱斯:索康尼(SAUCONY)
2017/08/09 全球购物
毕业生自荐书模版
2014/01/04 职场文书
优秀毕业生推荐信范文
2014/03/07 职场文书
2014年第四季度入党积极分子思想汇报(十八届四中全会)
2014/11/03 职场文书
2014年公务员转正工作总结
2014/11/07 职场文书
贷款收入证明范本
2015/06/12 职场文书
什么是检讨书?检讨书的格式及范文
2019/11/05 职场文书
python入门之算法学习
2021/04/22 Python
vue3使用vue-router的完整步骤记录
2021/06/20 Vue.js
mongodb清除连接和日志的正确方法分享
2021/09/15 MongoDB
海贼王十大潜力果实,路飞仅排第十,第一可毁世界(震震果实)
2022/03/18 日漫