Python 中如何检测某个字串包含其他字串? 0 个改进

可以使用 in 关键词:

"test" in "testtext"
True

"test" not in "testtext"
False

注意 in 是大小写敏感:


"abc" in "Abc"
False

"abc" not in "Abc"
True

in 还可以这样使用:

"abc" in ["abc", "def", "ghi"]
True
本文为 Wiki 文章,邀您参与纠错、纰漏和优化
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!