# 统计一个字符串中各个字符个数 # # words="hello word" # wordsCount={} # for i in words: # if i!=" ": # wordsCount[i]=0 # for i in words: # if i != " ": # wordsCount[i] +=1 # print(wordsCount) a = "hello" b = dict.fromkeys(a, 0) print(b) print("b[o] :",b["o"]) # print(b) for x in a: b[x]+=1 # print(b[x]) print(b)