How to Find the Longest Word in a Sentence in Python

sentence = "Python programming is amazing"
longest_word = max(sentence.split(), key=len)
print(f"Sentence: {sentence}\nLongest Word: {longest_word}")

Output:

Sentence: Python programming is amazing
Longest Word: programming

Leave a Comment

Your email address will not be published.