Problem:
Solution:
使用lstrip, rstrip, strip方法。
>>> x = ' hej '
>>> print '|', x.lstrip( ), '|', x.rstrip( ), '|', x.strip( ), '|'
| hej | hej | hej |
Discussion:
也可以指定要去除的元素,而不单单限于空白
>>>x = 'xyxxyy hejyx yyx'
>>>print '|'+x.strip('xy')+'|'
| hejyx |
Solution:
使用lstrip, rstrip, strip方法。
>>> x = ' hej '
>>> print '|', x.lstrip( ), '|', x.rstrip( ), '|', x.strip( ), '|'
| hej | hej | hej |
Discussion:
也可以指定要去除的元素,而不单单限于空白
>>>x = 'xyxxyy hejyx yyx'
>>>print '|'+x.strip('xy')+'|'
| hejyx |

浙公网安备 33010602011771号