Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python program to print even length words in a string

  • Difficulty Level : Easy
  • Last Updated : 26 Oct, 2018

Given a string. The task is to print all words with even length in the given string.


Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the  Demo Class for First Step to Coding Coursespecifically designed for students of class 8 to 12. 

The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.

Input: s = "This is a python language"
Output: This

Input: s = "i am muskan"
Output: am

Approach: Split the string using split() function. Iterate in the words of a string using for loop. Calculate the length of the word using len() function. If the length is even, then print the word.

Below is the Python implementation of the above approach:

# Python3 program to print 
#  even length words in a string 
def printWords(s):
    # split the string 
    s = s.split(' '
    # iterate in words of string 
    for word in s: 
        # if length is even 
        if len(word)%2==0:
# Driver Code 
s = "i am muskan" 
My Personal Notes arrow_drop_up
Recommended Articles
Page :