# 统计字符串中,各个字符的个数 # 比如:"hello world" 字符串统计的结果为: h:1 e:1 l:3 o:2 d:1 r:1 w:1 str_input = input("请输入字符串:") dict_str = {} for i in str_input: if i in dict_str: dict_str[i] += 1 else: dict_str[i] = 1 print(dict_str)
Python统计字符串中各个字符的个数
最新推荐文章于 2023-07-19 17:31:38 发布