Check If a Word Is in a Sentence
Beginner · Write the code · from Python Strings: Create, Access, Slice, and Manipulate Text
From the lesson: Python Strings: Create, Access, Slice, and Manipulate Text
Think about your phone. Almost everything you see on the screen is text: names in your contacts, messages from friends, search results, notifications. Behind the scenes, all of that text is handled by strings.
Read the lessonYou are given a sentence and a search_word. Check if the search word exists in the sentence (case-insensitive) and print the result.
Expected output:
TrueConvert both to the same case before checking.
sentence = "The quick brown Fox jumps over the lazy Dog"
search_word = "fox"
# Check if search_word is in sentence (case-insensitive)
# Print True or False
More Strings exercises
- Build a Greeting with ConcatenationBeginner
- Get the First and Last CharacterBeginner
- Reverse a StringBeginner
- Predict the Slice OutputBeginner
- Fix the Bug: Mutating a StringBeginner
- Extract a Domain from an Email AddressBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz