How to calculate the number of occurrences of a character in Python?
You can use the count() function to find the number of times a character appears in a string. The count() function takes a character as a parameter and returns the number of times that character appears in the string.
Here is an example:
s = "Hello, World!"
count = s.count("o")
print(count) # 输出:2
In the above example, the character “o” appears twice in the string s, so the output is 2.