DEV Community

Tania
Tania

Posted on • Originally published at kodlogs.com

Number of characters in a string python

Python Program to Count Total Characters in a String

Today we will learn about strings. We use strings more in computer language. Because now I'm talking to you, I'm talking in strings, not numbers. Similarly, when we make big programs. If so, it is important that we have enough knowledge about strings and the functions used in them. The more we practice, the more we will benefit. Using only strings in the program if we have a paragraph. My name is Tania. Now I want to know how many times my name appears in this paragraph. I will use the len function in my program. It helps me to know how many times my name appears. Let's use the concatenate function known as + to connect the string. If I concatenate the string, I can also use a comma, because it also helps us to connect the string. Let's look at some examples of how we try to find the number of characters in a string.

Example:

# Python Program to Count Total Characters in a String 
str1 = input("Please Enter your Own String : ") total = 0 i = 0 while(i < len(str1)): total = total + 1 i = i + 1 print("Total Number of Characters in this String = ", total)



           OUTPUT 
Please Enter your Own String : Wellcome to kodlogs 
Total Number of Characters in this String = 18
Enter fullscreen mode Exit fullscreen mode

Example :


# Python Program to Count Total Characters in a String
 str1 = input("Please Enter String : ")
 total = 0 for i in str1: total = total + 1 

print("Total Number of Characters in this String = ", total)
Enter fullscreen mode Exit fullscreen mode

image

Top comments (0)