Avoid spaces in string and get the total length

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
  1. Take a string as input.
  2. Use for loop to iterate over each character of the string.
  3. Use isspace() to check whether a character is a space or not.
  4. Find the total of such characters who are not space.
  5. 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
				
			

find permutations of a given string

accept a string that contains only vowels

Leave a Comment