By Editorial Staff. Updated on
Today we are going to share a Python program to remove a word from the sentence. If you are a python beginner and want to start learning the python programming, then keep your close attention in this program.
Want to increase your Python knowledge, practice all Python programs, here is a collection of 100+ Python problems with solutions.
Copy the below python program and execute it with the help of python compiler.
print("Enter 'x' for exit.");
string = input("Enter any string to remove particular word: ");
if string == 'x':
word = input("Enter word to be delete/remove: ");
print("\nDeleting given word from the given string...");
print("New String after successfully deleting",word);
word_list = string.split();
print(' '.join([i for i in word_list if i not in word]));
Enter any string to remove particular word: This is an example of the python program.
Enter word to be delete/remove: the
Deleting given word from the given string…
New String after successfully deleting ‘This is an example of python program.’
Same program in different programming langugaes:
Sharing is caring!