To remove or delete the occurrence of a given word from a given sentence or string in python, you have to ask from the user to enter the string and then ask to enter the word present in the string to delete all the occurrence of that word from the sentence and finally print the string without that word as shown in the program given below.
Following python program ask from the user to enter a string and a word to remove the word from the string and show/print the string without that word:
# Python Program - Remove Word from Sentence while True: print("Enter 'x' for exit.") string = input("Enter any string: ") if string == 'x': break else: word = input("Enter word to be delete: ") print("\nDeleting given word from the given string...") print("New String after successfully deleted the given word:") word_list = string.split() ' '.join([i for i in word_list if i not in word]) print("\n")
Here is the sample run of the above python program to illustrate how to remove word from sentence or string:
You may also like to learn or practice the same program in other popular programming languages: