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

yipeiwu_com5年前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在pycharm中的调试(debug)

浅谈Python在pycharm中的调试(debug)

作为一名程序员,调试(debug)程序是一项必会的事情,在利用pycharm这个pythonIDE时,不好好利用其调试功能真的是太可惜了。 借用这两天学习机器学习的工程。 在Deep_...

TensorFlow模型保存和提取的方法

TensorFlow模型保存和提取的方法

一、TensorFlow模型保存和提取方法 1. TensorFlow通过tf.train.Saver类实现神经网络模型的保存和提取。tf.train.Saver对象saver的save...

python 3利用Dlib 19.7实现摄像头人脸检测特征点标定

python 3利用Dlib 19.7实现摄像头人脸检测特征点标定

Python 3 利用 Dlib 19.7 实现摄像头人脸检测特征点标定 0.引言 利用python开发,借助Dlib库捕获摄像头中的人脸,进行实时特征点标定; 图1 工程效果示例(...

Window10下python3.7 安装与卸载教程图解

Window10下python3.7 安装与卸载教程图解

1.进入官网https://www.python.org/,点击Downloads下的Windows按钮,进入下载页面。 2.如下图所示,点击下载。 3.安装Python3.7.4...

python批量修改文件编码格式的方法

本文实例为大家分享了python批量修改文件编码格式的具体代码,供大家参考,具体内容如下 使用说明: 1、使用工具:Python2.7.6+chardet2.3.0,chardet2....