Saturday, 31 December 2022

Python program to search a word in a given string

  Python String  


Search a Word in a given String

  • We can use "in" keyword to search a word in a given string.

Example:


myText = "Wishing You All Happy and Healthy 2023 "
searchWord = "2023"

if (searchWord in myText):
    print(searchWord, "is present in myText variable")
else:
    print(searchWord, "is not present in myText variable")

Program Output :

      2023 is present in myText variable


Recommended Articles:

 


 Home 

 Next 

No comments:

Post a Comment