Python成员运算符
Python 运算符 成员
2023-09-11 14:21:27 时间
Python成员运算符:
in:如果左面的对象在右面的对象中,则返回 True,不在则返回 False。
not in:如果左面的对象不在右面的对象中,则返回 True,在则返回 False。
# 分别在列表、字符串、元组、字典和集合中使用。
# in 在则返回 True , 不在则返回 False
a = 'a'
d = 'd'
lst = ['a','b','c']
# 判断 a 是否在 lst 中
print(a in lst)
# True
# 判断 d 是否在 lst 中
print(d in lst)
# False
a = 'a'
d = 'd'
strs = 'abc'
# 判断 a 是否在 strs 中
print(a in strs)
# True
# 判断 d 是否在 strs 中
print(d in strs)
# False
a = 'a'
d = 'd'
tup = ('a','b','c')
# 判断 a 是否在 tup 中
print(a in tup)
# True
# 判断 d 是否在 tup 中
print(d in tup)
# False
a = 'a'
d = 'd'
dic = {'a':123,'b':456,'c':789}
# 判断 a 是否在 dic 中
# 字典主要是看,是否存在该键
print(a in dic)
# True
# 判断 d 是否在 s 中
print(d in dic)
# False
a = 'a'
d = 'd'
s = {'a','b','c'}
# 判断 a 是否在 s 中
print(a in s)
# True
# 判断 d 是否在 s 中
print(d in s)
# False
# not in , 不在返回 True ,在返回 False
# 分别在列表、字符串、元组、字典和集合中使用。
a = 'a'
d = 'd'
lst = ['a','b','c']
# 判断 a 是否不在 lst 中
print(a not in lst)
# False
# 判断 d 是否在 lst 中
print(d not in lst)
# True
a = 'a'
d = 'd'
strs = 'abc'
# 判断 a 是否不在 strs 中
print(a not in strs)
# False
# 判断 d 是否不在 strs 中
print(d not in strs)
# True
a = 'a'
d = 'd'
tup = ('a','b','c')
# 判断 a 是否不在 tup 中
print(a not in tup)
# False
# 判断 d 是否不在 tup 中
print(d not in tup)
# True
a = 'a'
d = 'd'
dic = {'a':123,'b':456,'c':789}
# 字典主要是看,是否存在该键
# 判断 a 是否不在 dic 中
print(a not in dic)
# False
# 判断 d 是否不在 dic 中
print(d not in dic)
# True
a = 'a'
d = 'd'
s = {'a','b','c'}
# 判断 a 是否不在 s 中
print(a not in s)
# False
# 判断 d 是否不在 s 中
print(d not in s)
# True
2020-02-05
相关文章
- Python 日期 的 加减 等 操作
- How to run python interactive in current file's directory in Visual Studio Code? Python路径问题
- 掌握Python语言能做什么?python对小白友好吗?
- 中途转行python?怎么学?没有基础的我30了自学Python转行靠谱吗?
- 人生苦短,我用Python!为什么现在越来越多的人转行python?
- 机器人系统设计与制作:Python语言实现1.5 本章小结
- Python数据可视化2.6 一些最好的可视化实践
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- Python爬虫技术--基础篇--数据类型和变量,标识符与关键字,运算符和表达式
- 源码编译vi过程中进行配置时报“checking if compile and link flags for Python are sane... no: PYTHON DISABLED”怎么办?
- python之实现ftp上传下载代码(含错误处理)
- 《Python面向对象编程指南》——2.6 比较运算符方法
- 《Python 3程序开发指南(第2版•修订版)》——2.5 实例
- Python 实现被动收入教程之我如何使用 python 制作我的第一个高级telegram机器人
- Python基础入门-函数参数
- Python爬虫之续Urllib&&Jsonpath库的使用
- 小学生python游戏编程arcade----动画图片实现爆炸效果
- python 多线程编程
- Python用python-docx读写word文档
- python selenium while 循环
- Python身份运算符
- gdb 使用python源码调试
- 不同操作系统Windows/Linux/MacOS中python环境通过pip安装mysqlclient遇到的问题及解决方案
- 【python】 字符串“-d aaa -i 10.xx.xxx.xx -p io“ 替换-i之后的字符串, 新思路
- python过滤非法字符