在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

相关文章

20招让你的Python飞起来!

今天分享的这篇文章,文字不多,代码为主。绝对干货,童叟无欺,主要分享了提升 Python 性能的 20 个技巧,教你如何告别慢Python。原文作者 开元,全栈程序员,使用 Python...

Python自动化部署工具Fabric的简单上手指南

Fabric 是基于 SSH 协议的 Python 工具,相比传统的 ssh/scp 方式,用 Python 的语法写管理命令更易读也更容易扩展,管理单台或者多台机器犹如本地操作一般。...

浅谈python的输入输出,注释,基本数据类型

1.输入与输出 python中输入与输出函数为:print、input help() 帮助的使用:help() help(print) print(value, ..., sep=...

pytorch::Dataloader中的迭代器和生成器应用详解

在使用pytorch训练模型,经常需要加载大量图片数据,因此pytorch提供了好用的数据加载工具Dataloader。 为了实现小批量循环读取大型数据集,在Dataloader类具体实...

python实现微信发送邮件关闭电脑功能

Python 通过微信邮件实现电脑关机,供大家参考,具体内容如下 通过手机微信发送QQ邮件给sina邮箱,然后利用python的pop3定时检查sina邮箱的邮件主题以及邮件来源,并在电...