How to check if a substring occurs in a string, ignoring case, in Python

A substring occurs in a string if the characters of the substring are found consecutively and in the same order in the string.

Solution for How to check if a substring occurs in a string, ignoring case, in Python : You can use str.find() with str.lower() to check if a substring occurs in a string, ignoring case Call str.find(substr) with str as the result of calling str.lower() on the base string and with substr as the result of calling str.lower() on the target substring. str.find(substr) will return the index the first occurrence of substr begins at in str, or -1 if substr is not in str. Therefore, to check if the target substring is in the string, verify that the result is greater than -1.


how-to-check-if-a-substring-occurs-in-a-string-ignoring-case-in-python