python中查找字符串中字符出现的次数
1、
>>> test1 = "absacaxy"
>>> test1.count("a") 3
>>> test1.count("a",0,4) ## 设置查找范围 2
2、统计所有字符出现的次数
>>> test1 = "abdeaceb"
>>> a = set(test1) >>> a {'d', 'e', 'c', 'b', 'a'} >>> for i in a: test1.count(i) 1
2
1
2
2
python中查找字符串中字符出现的次数
1、
>>> test1 = "absacaxy"
>>> test1.count("a") 3
>>> test1.count("a",0,4) ## 设置查找范围 2
2、统计所有字符出现的次数
>>> test1 = "abdeaceb"
>>> a = set(test1) >>> a {'d', 'e', 'c', 'b', 'a'} >>> for i in a: test1.count(i) 1
2
1
2
2
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。