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

在每个第 4 个字符上添加空格

  1. string = 'Test5412Test8745Test'
  2. print([string[i:i + 4] for i in range(0, len(string), 4)])

Output:

  1. ['Test', '5412', 'Test', '8745', 'Test']