Python program to print even length words in a string
Given a string. The task is to print all words with even length in the given string.
Examples:
Input: s = "This is a python language"
Output: This
is
python
language
Input: s = "i am muskan"
Output: am
muskan
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: print(word) # Driver Code s = "i am muskan" printWords(s) |
chevron_right
filter_none
Output:
Improved By : AnkitRai01
am muskan
Recommended Posts:
- Python Program to print all permutations of a given string
- Python program to print the substrings that are prefix of the given string
- Python | Extract words from given string
- Reverse words in a given String in Python
- Python program to count words in a sentence
- Python program to find uncommon words from two Strings
- Python | Program to crawl a web page and get most frequent words
- C program to find the length of a string
- Python string length | len()
- Find length of a string in python (4 ways)
- Python | Generate random string of given length
- Python | Padding a string upto fixed length
- Python Program for Efficient program to print all prime factors of a given number
- Find words which are greater than given length k
- Python Program for Program to Print Matrix in Z form
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnkitRai01



