当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

在Python中查找字符串中字符的所有位置

  1. test = 'canada#japan#uae'
  2. c = '#'
  3. print([pos for pos, char in enumerate(test) if char == c])

Output:

  1. [6, 12]

该分类下的相关小册推荐: