DEV Community

Tania
Tania

Posted on • Originally published at kodlogs.com

1 1

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️