📜  Python程序计算句子中的所有字符 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:03.239000             🧑  作者: Mango

代码示例1
#Python program count all characters in a text

root = "..\\Desktop\\text.txt"
file = open(root, 'rt', encoding="utf-8")
data = file.read()

counter = data.count('a')+data.count('A')+data.count('b')+data.count('B')+data.count('c')+data.count('C')+data.count('d')+data.count('D')+data.count('e')+data.count('E')+data.count('f')+data.count('F')+data.count('g')+data.count('G')+data.count('h')+data.count('H')+data.count('i')+data.count('I')+data.count('g')+data.count('G')+data.count('k')+data.count('K')+data.count('l')+data.count('L')+data.count('m')+data.count('M')+data.count('n')+data.count('N')+data.count('o')+data.count('O')+data.count('p')+data.count('P')+data.count('q')+data.count('q')+data.count('r')+data.count('R')+data.count('s')+data.count('S')+data.count('t')+data.count('T')+data.count('u')+data.count('U')+data.count('v')+data.count('V')+data.count('w')+data.count('W')+data.count('x')+data.count('X')+data.count('y')+data.count('Y')+data.count('z')+data.count('Z')

print(counter)
#684004