06-Mar-2023
.
Admin
Hi Dev,
Today, I will let you know example of how to count number of specific characters in python string. I explained simply step by step python count specific chat in string. This tutorial will give you simple example of how to count specific characters in a string python. you will learn python number of specific characters in string.
In this examples, i will add myString variable with hello string. Then we will use count() function to count number of specific character 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 Specific Characters
main.py
# Declare String Variable
myString = "Hello, This is nicesnippets.com:"
# Count Number Of Character from String
numberOfChar = myString.count("i")
print(numberOfChar)
Output:
4
#Python