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


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

Solution

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



List all Python Programs