📜  在字符串前后添加空格 python 代码示例

📅  最后修改于: 2022-03-11 14:46:30.480000             🧑  作者: Mango

代码示例1
using re adds white-space before and after the desired characters:

import re

pat = re.compile(r"([.()!])")
print (pat.sub(" \\1 ", string))
# hello .  .  .   ( world )  !