{"id":17595,"date":"2021-08-26T10:42:36","date_gmt":"2021-08-26T05:12:36","guid":{"rendered":"https:\/\/python-programs.com\/?p=17595"},"modified":"2021-11-22T18:37:12","modified_gmt":"2021-11-22T13:07:12","slug":"python-program-to-find-longest-word-from-sentence","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-longest-word-from-sentence\/","title":{"rendered":"Python Program to Find Longest Word from Sentence"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Move all Negative Elements to End in Order with Extra Space Allowed<\/a>
\nGiven a string and the task is to find the longest word from a given sentence.<\/p>\n

split() method:<\/strong><\/p>\n

The split() method in Python divides a string into a list of strings by breaking the string with the specified separator.<\/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 Longest Word in the above given sentence = btechgeeks\r\nThe length of the longest word = 10<\/pre>\n

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

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

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

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

The Longest Word in the above given sentence = Goodmorning\r\nThe length of the longest word = 11<\/pre>\n

Program to Find Longest Word from Sentence<\/h2>\n

Below are the ways to find the longest word from a given sentence.<\/p>\n