Python in 的逻辑判断

2023-10-13 18:56:41 浏览数 (1)

要看你的目标是什么

代码语言:javascript复制
1.字符串
 >>> "in" in "indigo"
 True
 >>> "in" in "violet"
 False
 >>> "0" in "10"
 True
 >>> "1" in "10"
 True
 2. 数组
 >>> "in" in ["in", "out"]
 True
 >>> "in" in ["indigo", "violet"]
 False
 3. 字典,是看key
 >>> "in" in {"in": "out"}
 True
 >>> "in" in {"out": "in"}
 False

0 人点赞