Answers for "how to check if a string contains a certain word in python"

PHP
2

How do I check if a string contains a specific word?

$a = 'Hello world?';

if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
    echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
    echo 'true';
}
Posted by: Guest on May-18-2020
53

python string contains

>>> str = "Messi is the best soccer player"
>>> "soccer" in str
True
>>> "football" in str
False
Posted by: Guest on December-09-2019
2

python check if string contains substring

string = "My favourite programming language is Python"
substring = "Python"

if substring in string:
    print("Python is my favorite language")
elif substring not in string:
    print("Python is not my favourite language")
Posted by: Guest on January-17-2021

Code answers related to "how to check if a string contains a certain word in python"

Browse Popular Code Answers by Language