Python in 的逻辑判断

python 中的in,要看你的目标是什么

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

http://www.waitingfy.com/archives/4591

猜你喜欢

转载自blog.csdn.net/fox64194167/article/details/80962291