Count all the values in a string.

In this program, we will take a string as input and count all the Uppercase, Lowercase, special character and numeric values in a given string.

Steps to solve the program
  1. Take a string as input.
  2. Create some variables and assign their values equal to 0.
  3. Use for loop to iterate over each character of the string.
  4. Check the type of the character and add 1 to the respective variable.
  5. Print the output.
				
					#Input string
str1 = "@SqaTools#lin"
upper = 0
lower = 0
digit = 0
symbol = 0

for val in str1:
    if val.isupper():
        upper += 1  
    elif val.islower():
        lower += 1
    elif val.isdigit():
        digit += 1
    else:
        symbol += 1
        
#Printing output
print("Uppercase: ", upper)
print("Lowercase: ", lower)
print("Digits: ", digit)
print("Special characters: ", symbol)
				
			

Output :

				
					Uppercase:  2
Lowercase:  9
Digits:  0
Special characters:  2
				
			

remove all characters except the given character in a string. 

count a number of non-empty substrings of a given string.

Leave a Comment