Nathan P. answered 03/22/19
Tutor
4.9
(36)
MS in Computer Science with 5+ years of Programming Work Experience
Another way this could be done is by using the "in" keyword. Note that the "in" keyword is particularly powerful because it can be used for many different applications such as checking if a substring is in a string, checking if an item is in a list, checking if an item is in a set, among others uses. The time complexity of the "in" function is O(N) on average where N is the size of the string, list, set, etc. because worst case scenario we look through a whole string and don't find the substring we are looking for. https://www.w3schools.com/python/ref_keyword_in.asp
"""
the way that we can check if something is inside something else using the
"in" function is through the syntax:
if sub_string in string:
"""
string = "ab"
substring = "a"
if substring in string:
print("Found") #this will be printed
else:
print("Not Found")