Chopping off spaces at both ends

  • Thread starter Madhusudan Singh
  • Start date
M

Madhusudan Singh

Hi

I am a newbie to python and am using it to interface some of my lab
equipment.

How does one get rid of spaces at both ends of a string ? A little like the
trim() intrinsic in fortran 95.

One of my instruments is returning a string that has one or more blanks in
it, and that is complicating string matching tests in one of my functions.

Thanks.
 
K

Kay Schluehr

Use the strip() method.

Example:
"abc"

Variants are lstrip() and rstrip().

Regards,
Kay
 
B

Bengt Richter

Use the strip() method.

Example:

"abc"

Variants are lstrip() and rstrip().

and also occasionally useful:
'123'

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.

Regards,
Bengt Richter
 
T

Tim Roberts

Madhusudan Singh said:
I am a newbie to python and am using it to interface some of my lab
equipment.

How does one get rid of spaces at both ends of a string ? A little like the
trim() intrinsic in fortran 95.

One of my instruments is returning a string that has one or more blanks in
it, and that is complicating string matching tests in one of my functions.
'abc'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top