Python Practice › String Programs › Program 92

Length without spaces

EasyString Programs · 92 of 106

Write a Python program to get the length of a string, not counting spaces.

Advertisement
Input
"sqatools is best for learning python"
Output
31

Approach

  1. Remove spaces, then use len().

Solution

Python
text = "sqatools is best for learning python"print(len(text.replace(" ", "")))
Output
31
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs