Python program to print even length words in a string

Python program to print even length words in a string

Here's a simple Python program that prints even length words from a given string:

def print_even_length_words(s): # Split the string into words words = s.split() # Iterate through the words and print those with even lengths for word in words: if len(word) % 2 == 0: print(word) # Test the function input_string = "Hello world this is a test" print_even_length_words(input_string) 

When you run this program with the given input_string, it will print:

world this is test 

These are the words in the string that have even lengths.


More Tags

pageable video-recording conv-neural-network microcontroller printf podfile exceldatareader python-embedding verify jmeter-3.2

More Programming Guides

Other Guides

More Programming Examples