具体操作如下:

id = 'WeWillBeTogetherForever'
pos = id.find('e')    #此处id.find返回的参数为字符在其出现的位置
count = 0    #设定次数容器

因为只返回的话只返回一次,所以用while循环实现次功能

id = 'WeWillBeTogetherForever'
pos = id.find('e')    #此处id.find返回的参数为字符在其出现的位置
while pos !=-1:
    count = count + 1
    print('e出现在第{}个位置'.format(pos))
    pos = (id.find('e',pos+1))
print('e共出现了{}次'.format(id.count('e')))

运行结果如下:

python 在字符串中查找字符出现次数 python查找字符出现的次数_while循环