Strings are pretty powerful and python has a diverse set of utilities to work with them. Some applications require checking if a string appears in another string. When searching a word on a website (Ctrl + F), we want to check if the word we typed appears in the text of the website.
In python, checking if a string appears in another string can be done with the in keyword:
word = 'access'
text = 'The entire house was accessible through that underground tunnel'
if word in text:
print('Yes, the word is in the text')
else:
print('Not found...')
It’s not mandatory for the first string to be only a word. It can be an arbitrary string. We can check for if 'some string with symb$ls' in text:.
Challenge
You are developing a chatbot. You would like to identify if a message was a greeting message. To do that you want to know if the message contains Hi, hi, Hello, or hello in it.
Given a text, your task is to print Yes if the text is a greeting message and No otherwise.