Python Practice › String Programs › Program 92
Length without spaces
Write a Python program to get the length of a string, not counting spaces.
Input
"sqatools is best for learning python"
Output
31
Approach
- Remove spaces, then use
len().
Solution
text = "sqatools is best for learning python"print(len(text.replace(" ", "")))Output
31
Learn the concept
New to this topic? Read the lesson, then come back.