gpt4 book ai didi

php - 什么是 strpos($elem ,"text") !== false) 的 python 等价物

转载 作者:可可西里 更新时间:2023-10-31 22:06:10 28 4
gpt4 key购买 nike

什么是 python 等同于:

if (strpos($elem,"text") !== false) {
// do_something;
}

最佳答案

找不到时返回-1:

pos = haystack.find(needle)
pos = haystack.find(needle, offset)

未找到时引发 ValueError:

pos = haystack.index(needle)
pos = haystack.index(needle, offset)

要简单地测试子字符串是否在字符串中,请使用:

needle in haystack

相当于下面的 PHP:

strpos(haystack, needle) !== FALSE

来自 http://www.php2python.com/wiki/function.strpos/

关于php - 什么是 strpos($elem ,"text") !== false) 的 python 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143267/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com