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

yipeiwu_com6年前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实现雪花算法过程详解

基于python实现雪花算法过程详解

这篇文章主要介绍了基于python实现雪花算法过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 Snowflake是Twitte...

Python的matplotlib绘图如何修改背景颜色的实现

Python的matplotlib绘图如何修改背景颜色的实现

在主图中背景颜色不知道怎么改,plt.plot()中没有axisbg参数。 但是子图可以对plt.subplot的参数做修改,下面是对子图的背景颜色修改代码 import matpl...

HTML的form表单和django的form表单

HTML的form表单和django的form表单

django的表单系统,分2种 基于django.forms.Form的所有表单类的父类 基于django.forms.ModelForm,可以和模型类绑定的Form 直接用...

python之pandas用法大全

一、生成数据表 1、首先导入pandas库,一般都会用到numpy库,所以我们先导入备用: import numpy as np import pandas as pd 2、导入C...

Python查找函数f(x)=0根的解决方法

本文实例讲述了Python查找函数f(x)=0根的解决方法。分享给大家供大家参考。具体实现方法如下: ''' root = ridder(f,a,b,tol=1.0e-9). F...