python method of clearing the space function before and after a string

  • 2020-12-21 18:06:21
  • OfStack

python does not work with regular re.sub, which sometimes needs to clear the Spaces before and after a string, but the Spaces of the characters themselves do not.

This is where the strip() function comes in

Usage:


str = '  2014-04-21 14:10:18  '
str2 = str.strip()
str3 = re.sub(' ','',str)
 
print str2
print str3
 The results are as follows: 
>2014-04-21 14:10:18
>2014-04-2114:10:18

Related articles: