在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

相关文章

pytorch 利用lstm做mnist手写数字识别分类的实例

代码如下,U我认为对于新手来说最重要的是学会rnn读取数据的格式。 # -*- coding: utf-8 -*- """ Created on Tue Oct 9 08:53:25...

python文件操作之目录遍历实例分析

本文实例讲述了python文件操作之目录遍历的方法。分享给大家供大家参考。具体分析如下: Python的os模块,包含了普遍的操作系统功能,这里主要学习与路径相关的函数: os.list...

Python3.2模拟实现webqq登录

这是我最初学习时自己做的一个python模拟登录webqq的实例代码,具体代码如下 import hashlib from urllib import request,parse f...

Python安装第三方库及常见问题处理方法汇总

源码安装 Python第三方库几乎都可以在github或者 pypi上找到源码。源码包格式大概有zip 、 tar.zip、 tar.bz2。解压这些包,进入解压好的文件夹,通常会有一个...

使用Python判断IP地址合法性的方法实例

使用Python判断IP地址合法性的方法实例

一、使用方法和执行效果请看图:二、python实现代码:复制代码 代码如下:[root@yang python]# vi check_ip.py #!/usr/bin/python im...