Chopping off spaces at both ends

Bengt Richter bokr at
Mon Aug 8 00:25:34 CEST 2005

On 7 Aug 2005 10:14:33 -0700, "Kay Schluehr" <kay.schluehr at> wrote:

>Use the strip() method.
>>>> "\t abc    \n".strip()
>Variants are lstrip() and rstrip().

and also occasionally useful:

 >>> 'abc123cab'.strip('bca')

I.e., a strip argument as an unordered set of characters that
causes stripping so long as characters at the end(s) of the
string being stripped are found that are in the set.

Bengt Richter

More information about the Python-list mailing list