Python Program to find the length of the longest word in a given sentence
You can achieve this in Python using a simple function. Here's a Python program to find the length of the longest word in a given sentence:
def longest_word_length(sentence):
words = sentence.split() # Split the sentence into words
max_length = 0
for word in words:
if len(word) > max_length:
max_length = len(word)
return max_length
# Example usage:
sentence = "The quick brown fox jumps over the lazy dog"
print("Length of the longest word:", longest_word_length(sentence))
```
This program defines a function `longest_word_length` that takes a sentence as input and returns the length of the longest word in it. It splits the sentence into words using the `split()` method, iterates over each word to find its length, and updates the `max_length` variable if a longer word is found. Finally, it returns the `max_length`.