Removing surrounding whitespace

0 votes
Is there a Python function that deletes whitespace that surround a string?
May 4, 2018 in Python by kaalabilli
• 1,090 points
41 views

1 answer to this question.

0 votes

Try the strip() function: 

s = s.strip()

If you want to strip the string of whitespaces on only one side, use the analogous lstrip() or rstrip() functions.

answered May 4, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
1 answer

Extract element from a set without removing it

Use iter(): element = next(iter(set_1)) READ MORE

answered Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
19 views
0 votes
1 answer

Python Whitespace for indenting

PEP-8 recommends creating indents by tapping the ...READ MORE

answered Jun 12, 2018 in Python by Hamartia's Mask
• 1,580 points
35 views
+1 vote
1 answer

How do I trim whitespace?

Whitespace on both sides: s = " \t ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 56,520 points
27 views
+1 vote
2 answers

Remove all whitespace in a string in Python

You can also use regular expressions for ...READ MORE

answered Aug 31, 2018 in Python by Omkar
• 67,460 points
1,562 views
0 votes
1 answer

How to Pivot pandas for removing of some headers and renaming of some indexes?

Solution is add parameter values to pivot, then add reset_index for column ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 56,520 points
780 views
0 votes
2 answers

Removing Title bar in Tkinter program

you can remove the title bar by ...READ MORE

answered Mar 19 in Python by anonymous
1,395 views
+4 votes
6 answers
0 votes
1 answer