What is the python equivalent of:
if (strpos($elem,"text") !== false) {
// do_something;
}
The strpos() function finds the position of the first occurrence of a string inside another string.
strpos() Function: This function helps us to find the position of the first occurrence of a string in another string. This returns an integer value of the position of the first occurrence of the string. This function is case-sensitive, which means that it treats upper-case and lower-case characters differently.
The stripos() function finds the position of the first occurrence of a string inside another string. Note: The stripos() function is case-insensitive. Note: This function is binary-safe. Related functions: strripos() - Finds the position of the last occurrence of a string inside another string (case-insensitive)
pos = haystack.find(needle)
pos = haystack.find(needle, offset)
pos = haystack.index(needle)
pos = haystack.index(needle, offset)
To simply test if a substring is in a string, use:
needle in haystack
which is equivalent to the following PHP:
strpos(haystack, needle) !== FALSE
From http://www.php2python.com/wiki/function.strpos/
if elem.find("text") != -1:
do_something
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With