
上QQ阅读APP看书,第一时间看更新
4.7 成员运算符和成员表达式

↑扫码看视频
成员运算符的功能是测试在成员组中是否包含某个成员,成员可以是字符串、列表或元组。在本节中,将详细讲解Python成员运算符和成员表达式的基本知识。
Python中的成员运算符有两个,分别是in和not in。具体说明见表4-6。
表4-6 成员运算符说明

如果读者还是不太理解成员运算符的具体含义,可以看看下面的这两句话。
● My dog is in the box(狗在盒子里)。
● My dog is not in the box(狗不在盒子里)。
in和not in会返回一个布尔值,为真表示“在”的情况,为假则表示“不在”的情况。

实例文件chengyuan.py的具体实现代码如下所示。

在上述代码中用到了List列表的知识,这部分内容将在第7章进行讲解,本实例执行后输出的结果如下所示。
