
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print even length words in a string
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given a string we need to display all the words in the string with even length.
Approach
Split the input string using the split() function.
Iterate over the words of a string using for a loop & Calculate the length of the word using len() function.
If the length evaluates to be even, word gets displayed on the screen.
Otherwise, no word appears on the screen.
Now let’s see the implementation given below −
Example
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) # main s = "tutorial point" printWords(s)
Output
tutorial
All the variables and functions are declared in the global scope as shown below −
Conclusion
In this article, we learned about the approach to print even length words in a string.
- Related Questions & Answers
- Java Program to Print even length words
- Reversing the even length words of a string in JavaScript
- Python program to print even numbers in a list
- Java Program to Print all unique words of a String
- Python program to print all even numbers in a range
- Python program to Count words in a given string?
- Check if a string contains a palindromic sub-string of even length in Python
- Python program to print Possible Words using given characters
- Print Words Vertically in Python
- C++ program to print unique words in a file
- Print all funny words in a string in C++
- Program to find maximum length of non-sharing words in Python
- Python Program to Print Largest Even and Largest Odd Number in a List
- C# program to Reverse words in a string
- Program to find length of longest path with even sum in Python
Advertisements