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 

Monday 11 July 2022

Python program to reverse a given string

  Python String  

Python program to reverse a given string. 

This program will read a string from user and prints reversed string.

Program Code :

# Python program to reverse a given string.

str=input("Enter your string:")
print("The original string is : " + str)

str_rev = str[::-1]
print("The reversed string is : " + str_rev)

Program Output :

Enter your string:Python Practicals 

The original string is : Python Practicals 

The reversed string is : slacitcarP nohtyP

Recommended Articles:

 


 Home 

 Next