In Python, how to count the number of occurrences of a character in a string?
In Python, it is possible to count the number of occurrences of a given character with the count()
function. Here is an example with the letter c
:
string.count('c')
The following example displays 2:
string = "Answiki"
n = string.count('i')
print (n)
Try this example online on repl.it.
In Python, it is possible to count the number of occurrences of a given character with the count()
function. Here is an example with the letter c
:
string.count('c')
The following example displays 2:
string = "Answiki"
n = string.count('i')
print (n)
Try this example online on repl.it.
In Python, it is possible to count the number of occurrences of a given character with the count()
function. Here is an example with the letter c
:
string.count('c')
The following example displays 2:
string = "Answiki"
n = string.count('i')
print (n)
Try this example online on repl.it.
# | ID | Query | URL | Count |
---|