In this program, we will take a string as input and avoid spaces in the string and get the total length.
Steps to solve the program
- Take a string as input.
- Use for loop to iterate over each character of the string.
- Use isspace() to check whether a character is a space or not.
- Find the total of such characters who are not space.
- Print the output.
#Input string
str1 = "sqatools is best for learning python"
result = sum(not char.isspace() for char in str1)
#Printing output
print("Length :",result)
Output :
Length : 31