大家讲道理2017-04-18 10:09:54
You can use the re.sub function to perform regular replacement,
sub(pattern, repl, string, count=0)
First parameter: Rule
The second parameter: the replaced string
The third parameter: string
The fourth parameter: the number of replacements. Defaults to 0, meaning every match is replaced
>>> a="\t\t\n 123"
>>> a
'\t\t\n 123'
>>> b = re.sub(r'\s+','', a) #\s 匹配任意的空白符
>>> b
'123'