Like a persistent treasure hunter, you found each "secret"
, no matter how well it was hidden! In the process, you learned that the best way to check whether a string contains a substring in Python is to use the in
membership operator.
You also learned how to descriptively use two other string methods, which are often misused to check for substrings:
.count()
to count the occurrences of a substring in a string.index()
to get the index position of the beginning of the substring
After that, you explored how to find substrings according to more advanced conditions with regular expressions and a few functions in Python’s re
module.
Finally, you also learned how you can use the DataFrame method .str.contains()
to check which entries in a pandas DataFrame contain a substring .