小册名称:Python合辑4-130个字符串操作示例
在Python中查找字符串中字符的所有位置
test = 'canada#japan#uae'c = '#'print([pos for pos, char in enumerate(test) if char == c])
test = 'canada#japan#uae'
c = '#'
print([pos for pos, char in enumerate(test) if char == c])
Output:
[6, 12]