在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错误调试及单元文档测试过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 错误分为程序的错误和由用户...

python3实现短网址和数字相互转换的方法

本文实例讲述了python3实现短网址和数字相互转换的方法。分享给大家供大家参考。具体实现方法如下: import math import decimal def convert_t...

python简单贪吃蛇开发

本文实例为大家分享了python简单贪吃蛇的具体代码,供大家参考,具体内容如下 import sys import random import pygame from pygame....

Python中用于转换字母为小写的lower()方法使用简介

 lower()方法返回所有基于大小写的字符被转换为小写字符串的一个副本。 语法 以下是lower()方法的语法: str.lower() 参数  &...

python读取有密码的zip压缩文件实例

python读取有密码的zip压缩文件实例

今天试了一下用zipfile模块读取有密码的zip压缩文件。 今天用winrar 5.6将一个名字为1.xlsx的excel文件打包成1.zip压缩包。采用默认的压缩算法(没有勾选传统加...