什么是操作符?
简单的回答可以使用表达式4 + 5等于9,在这里4和5被称为操作数,+被称为操符。 Python语言支持操作者有以下几种类型。
算术运算符
比较(即关系)运算符
赋值运算符
逻辑运算符
位运算符
会员操作符
标识操作符
下面简单介绍一下,Python的成员运算符,下表列出了所有Python语言支持的成员运算符。操作符描述示例
in计算结果为true,如果它在指定找到变量的顺序,否则false。x在y中,在这里产生一个1,如果x是序列y的成员。
not in计算结果为true,如果它不找到在指定的变量顺序,否则为false。x不在y中,这里产生结果不为1,如果x不是序列y的成员。
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