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
785 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
1,257 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
649 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
• 58,020 points
681 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
• 69,220 points
17,178 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
• 58,020 points
21,684 views
0 votes
2 answers

Removing Title bar in Tkinter program

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

answered Mar 19, 2019 in Python by anonymous
20,436 views
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,109 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP