how to check if a string contains a specific word in python code example
Example 1: How do I check if a string contains a specific word?
$a = 'Hello world?';
if (strpos($a, 'Hello') !== false) {
echo 'true';
}
if (stripos($a, 'HELLO') !== false) {
echo 'true';
}
Example 2: python string contains substring
fullstring = "StackAbuse"
substring = "tack"
if fullstring.find(substring) != -1:
print "Found!"
else:
print "Not found!"
Example 3: python str contains word
fullstring = "StackAbuse"
substring = "tack"
if substring in fullstring:
print "Found!"
else:
print "Not found!"
Example 4: python check if string
type('hello world') == str
# output: True
type(10) == str
# output: False
Example 5: python check if value in string
def is_value_in_string(value: str, the_string: str):
return value in the_string.lower()