codescracker


python

Python Program to Remove Word from Sentence



« Previous Program Next Program »


Remove Word from Sentence in Python

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.

Python Programming Code to Remove Word from Sentence

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:

python remove word from sentence

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test