在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决策树之CART分类回归树详解

python决策树之CART分类回归树详解

决策树之CART(分类回归树)详解,具体内容如下 1、CART分类回归树简介   CART分类回归树是一种典型的二叉决策树,可以处理连续型变量和离散型变量。如...

对python中的装包与解包实例详解

*args和 **kwargs是常用的两个参数 *args:用于接受多余的未命名的参数,元组类型。 **kwargs:用于接受形参的命名参数,字典类型的数据。 可变参数args: d...

python 串口读取+存储+输出处理实例

研究了一晚上的成果。 import serial import win32com.client import matplotlib.pyplot as plt import...

python 多线程将大文件分开下载后在合并的实例

废话不多说了,上代码吧: import threading import requests import time import os class Mythread(thread...

Python3 循环语句(for、while、break、range等)

Python3 循环语句(for、while、break、range等)

本章节将为大家介绍Python循环语句的使用。 Python中的循环语句有 for 和 while。 Python循环语句的控制结构图如下所示: while 循环 Python中whi...