How to Count Number of Characters in Python String?

01-Mar-2023

.

Admin

How to Count Number of Characters in Python String?

Hi Dev,

This article is focused on how to count number of characters in python string. if you want to see example of python string count number of characters then you are a right place. This article goes in detailed on python program to count number of characters in string. I would like to share with you python count number of char in string. Alright, let’s dive into the steps.

In this examples, i will add myString variable with hello string. Then we will use len() function to count number of characters from string in python. So, without further ado, let's see simple examples: You can use these examples with python3 (Python 3) version.

Python String Count Number of Characters


main.py

# Declare String Variable

myString = "Hello, This is nicesnippets.com"

# Count Number Of Character from String

numberOfChar = len(myString)

print(numberOfChar)

Output:

34

#Python