Write Python3 code to demonstrate working of Rear word replace in String using rfind() + join()


Topic: Write Python3 code to demonstrate working of Rear word replace in String using rfind() + join()

Solution

test_str = "GFG is good"
print("The original string is : " + test_str) 
rep_str = "best"
res = test_str[: test_str.rfind(' ')] + ' ' + rep_str 
print("The String after performing replace : " + res) 



List all Python Programs