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

yipeiwu_com5年前Python基础

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

2015513122253479.jpg (586×176)

 例如:

试试下面的例子就明白了所有的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 SQLAlchemy基本操作和常用技巧(包含大量实例,非常好)

首先说下,由于最新的 0.8 版还是开发版本,因此我使用的是 0.79 版,API 也许会有些不同。因为我是搭配 MySQL InnoDB 使用,所以使用其他数据库的也不能完全照搬本文。...

Python实现获取前100组勾股数的方法示例

本文实例讲述了Python实现获取前100组勾股数的方法。分享给大家供大家参考,具体如下: 本来想采用穷举试探的方式来做这个算法,后来发现还是有点麻烦。从网络上找来了一种求解方法如下:...

python图像处理之镜像实现方法

python图像处理之镜像实现方法

本文实例讲述了python图像处理之镜像实现方法。分享给大家供大家参考。具体分析如下: 图像的镜像变化不改变图像的形状。图像的镜像变换分为三种:水平镜像、垂直镜像、对角镜像 设图像的大小...

ptyhon实现sitemap生成示例

复制代码 代码如下:# _*_ coding:utf-8 _*_ #xiaohei.python.seo.call.me:)#win+python2.7.x id_ = 1f = ope...

python和pyqt实现360的CLable控件

 复制代码 代码如下: #!/usr/bin/python  #-*-coding:utf-8-*- from PyQt4.QtGui import *fr...