小册名称:Python合辑4-130个字符串操作示例
在 Python 中的数字和字符串之间添加空格
import res = "ABC24.00XYZ58.28PQR"s = re.sub("[A-Za-z]+", lambda group: " " + group[0] + " ", s)print(s.strip())
import re
s = "ABC24.00XYZ58.28PQR"
s = re.sub("[A-Za-z]+", lambda group: " " + group[0] + " ", s)
print(s.strip())
Output:
ABC 24.00 XYZ 58.28 PQR