# Python program to remove a given word from a string.
def removeWord(string, word):
# Check if the word is present in string
if word in string:
# To cover the case if the word is at the beginning
# of the string or anywhere in the middle
tempWord = word + " "
string = string.replace(tempWord, "")
# To cover the edge case if the word is at the end
# of the string
tempWord = " " + word
string = string.replace(tempWord, "")
# Return the resultant string
return string
# Test Case 1 :
# If the word is in the middle
string1 = "Geeks for Geeks."
word1 = "for"
# Test Case 2 :
# If the word is at the beginning
string2 = "for Geeks Geeks."
word2 = "for"
# Test Case 3 :
# If the word is at the end
string3 = "Geeks Geeks for."
word3 = "for"
# Test Case 4 :
# If the word is not present
string4 = "A computer Science Portal."
word4 = "Geeks"
# Test case 1
print("String:", string1, "\nWord:", word1,
"\nResult String:", removeWord(string1, word1))
# Test case 2
print("\nString:", string2, "\nWord:", word2,
"\nResult String:", removeWord(string2, word2))
# Test case 3
print("\nString:", string3, "\nWord:", word3,
"\nResult String:", removeWord(string3, word3))
# Test case 4
print("\nString:", string4, "\nWord:", word4,
"\nResult String:", removeWord(string4, word4))
# This code is contributed by lokeshmvs21.