{"id":20027,"date":"2021-09-06T13:33:15","date_gmt":"2021-09-06T08:03:15","guid":{"rendered":"https:\/\/python-programs.com\/?p=20027"},"modified":"2021-11-22T18:36:29","modified_gmt":"2021-11-22T13:06:29","slug":"python-program-to-remove-the-last-word-from-the-string-sentence","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-remove-the-last-word-from-the-string-sentence\/","title":{"rendered":"Python Program to Remove the last Word from the String\/Sentence"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Print Palindrome Numbers in a Range<\/a><\/p>\n

Given a string\/sentence and the task is to remove the last word from the given sentence.<\/p>\n

join()<\/strong> :<\/p>\n

The string method join()\u00a0 takes all of the items in an iterable and returns a string after joining them all together. Iterable types include list, tuple, string, dictionary, and set.<\/p>\n

pop() Function in Python:<\/strong><\/p>\n

Python’s list pop() function removes and returns the final value from a List or the supplied index value.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = \"Hello this is btechgeeks\"<\/pre>\n

Output:<\/strong><\/p>\n

The given string{ Hello this is btechgeeks } after removal of last word = Hello this is<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = \"Good Morning btechgeeks Hello everyone\"<\/pre>\n

Output:<\/strong><\/p>\n

The given string{ Good Morning btechgeeks Hello everyone } after removal of last word =  Good Morning btechgeeks Hello<\/pre>\n

Program to Remove the last Word from the String\/Sentence in Python<\/h2>\n

Below are the ways to remove the last word from a given string\/sentence:<\/p>\n