在python API中这样解释strip()函数:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+EAAABmCAIAAAArhgdMAAATe0lEQVR4nO2d0bHbOhJEGZQzcjwOx8m8GPZjqzYA7se19SgCaPQMQRLUPadcLokAZhoDEGzLsu+yAgAAAADATCx3CwAAAAAAgDfw6AAAAAAAc4FHBwAAAACYCzw6AAAAAMBc4NEBAAAAAOYCjw4AAAAAMBd4dAAAAACAucCjAwAAAADMBR4dAAAAAGAu8OgPYNlwt5Y+z1ILAAAAMCG4qNvwLexDzW4p+6ETAQAAALgYPNM9hNzqQ61tVfZD5wIAAABwJRimDP/8+rEsy7L8+PVPZnjUpz7U17ZkP3Q6AAAAAJeBW8qAR3fAowMAAADk+I5u6ffPZVl+/r4pe8KhnmdqT7XLIjg2HQAAAEBwkVWa6X/5+PoQHI9+ulHGowMAAADkyFul6L96nMSW/f2aCh4djw4AAAAwKRd59Kv468A3vL4z/vvnvml5c+ub9p+/3yJtvnb+lmD3dfS/AX7+fk/13k071y3OEAcdttUkRm2vtLp1Z3pkRgAAAACfTccqOQZud3Ft27gysm6tNrX545//eu7GJ+a7XtUgP378WJblx69//pjtovNXkPKfjP5r4f8MKUW0piMM7hFH2wpbXdZWut0oR7OWjUcHAAAAECirpG1i1WbtrLnu73jEiJkrjXPtX4c6Hr3qv3WqZvD9JdOjm02aUEyns+/Co9kBAAAA4EXSY7Vaj5jCwx59ffu+SstkWx69958qBjz6H02vvrpE1b83uN6jLwViVFVzNDsAAAAAvHC/61JtMi+2msSHsiKvxb/fOSl89MQe/dUh9HG1iOM3bV2482encnjug3kAAAAAKHGtkunAhn+OHuDrm+RvtvnLHr/b8Xcb/c+vH7Wvpgz06PuvtDt1u9ejm01dkXh0AAAAgBzjv4/uRKteaX3XYnexrbf4B551J735XLvyX6UP8ejFPxnt/dcuiVKL66/WVvVCRtzx6KHNgEEHAAAA0PRNnnDGOwPX6l9tEm9bXtD06O/UvtOy7five64MV/9xS7XX5n+FERLKWehSi/q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AAPdyjzVZ3qm2rgc8utkkcrXSaeWtpN230VKEgmxbq6HKgOY0deoyyE5AtA5af1eMnq+eIwAAAMCVfJo16TozAAAAAIDJ+UAL638ADAAAAAAwIbhYAAAAAIC5wKMDAAAAAMwFHh0AAAAAYC7w6AAAAAAAc4FHBwAAAACYCzw6AAAAAMBc/B+l8YxApY2jugAAAABJRU5ErkJggg==" alt="" />
声明:s为字符串,rm为要删除的字符序列
s.strip(rm) 删除s字符串中开头、结尾处,位于 rm删除序列的字符
s.lstrip(rm) 删除s字符串中开头处,位于 rm删除序列的字符
s.rstrip(rm) 删除s字符串中结尾处,位于 rm删除序列的字符
注意:
1. 当rm为空时,默认删除空白符(包括'\n', '\r', '\t', ' ')
例如:
>>> a=' Hello World '
>>> a
' Hello World '
>>> a.strip()
'Hello World' >>> x='\t\r\npython'
>>> x
'\t\r\npython'
>>> x.strip()
'python'
2.rm删除序列是只要边(开头或结尾)上的字符在删除序列内,就删除掉。
例如:
>>> aString='123love'
>>> aString
'123love'
>>> aString.strip('')
'3love'