Program For Search word in Your Sentence

Program For Search word in Your Sentence

This Python code prompts the user to input a word and a sentence, and uses regular expressions to check if the word appears in the sentence.

Code:

# Import the regular expression library
import re  
# Prompt the user to enter a word 
word = input("Enter Your Word : ")
# Prompt the user to enter sentence 
sentence = input("Enter sentance : ") 

# Use regular expressions to search for the word in the sentence 
search = re.search(word,sentence) 
# Check if the search was successful, and print a message accordingly 
if search : 
    print("Yes Your Word Found in your sentence") 
else: 
    print("No Your Word not Found in your sentence")

Code Explanation:

This Python code get the user to input a word and a sentence, and uses regular expressions to check if the word appears in the sentence. 

The re.search() function searches for the given pattern (in this case, the word variable) in the given string (the sentence variable), and returns a match object if a match is found. The if search: statement checks if the match object is truly, meaning that the word was found in the sentence. If it was, the code prints a message (Yes Your Word Found in your sentence). If not, it prints a message (No Your Word not Found in your sentence).

LIKE | SHARE | AND SUBSCRIBE 👇👇👇