Count the number of small letters in a string in Python

Hey guys

In this tutorial, we will learn how to count the number of capital letters in a given string.

first, we will know what is our problem. we have a given string that contains the number of the lower case letters and the number of upper case letters. Now we have to write such a type of code that counts the number of the lowercase letters in the string and print it as the output on the string.

Now let’s move towards our coding portion.

Finding the number of lowercase letters in the string

first, we know how to take the input string from the user

name=input("enter the string")

or we can use another method for accepting string because the above can accept any type of data as a string

name=str(input("enter the string))

islower() function does not contain any parameter

  • It will return true if all the letters in the string are in lowercase
  • it will return false if the string contains one or more uppercase letters

Now let us  move towards the  coding portion of the problem



name=str(input("enter the string:-"))
count=0
for i in name:
    if i.islower():
        count=count+1
print("Nmber of small latter in our string is:-",count)

According to the above piece of code,  the variable of the string is called name. and a counter variable will be initialized count=0 which is used to count the number of small letters. now we start a for loop using the values of the name as i then if statement checks that the character is in lowercase or not if yes, then if block will execute, otherwise the loop will continue till the last character of the string and checks each and every character.

Now the output will be:-

enter the string:-this IS my first PROgram
Nmber of small latter in our string is:- 15

As we can see there are a total of 15 small letters in the given string

you can also check for

Rename multiple files in python

A simple Candy Machine in Python

 

Leave a Reply

Your email address will not be published. Required fields are marked *