Editor settings

General settings

Save settings

Learn to program with Python

Find the longest word in a string #

Write a function that takes a sentence as input and returns the longest word from the sentence. If there are multiple words with the same maximum length, the function should return the first occurrence.


Tests #

  • get_longest_word("Hello world") should return "Hello"
  • get_longest_word("The cat in the hat") should return "The"
  • get_longest_word("Today is a beautiful day") should return "beautiful"
  • get_longest_word("Python is a powerful programming language") should return "programming"
  • get_longest_word("The quick brown fox jumps over the lazy dog") should return "quick"
Output will be displayed here