- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove all trailing and leading whitespace in a string in Python?
To remove all trailing and leading whitespace in a string, we can use the method strip() in String class that gets rid of both these whitespaces. You can use it as follows:
>>> ' Hello People '.strip() 'Hello People'
If you only want to remove leading or trailing whitespace use lstrip() or rstrip() respectively.
>>> ' Hello People'.lstrip() 'Hello People' >>> 'Hello People '.rstrip() 'Hello People'
- Java Program to remove leading and trailing whitespace from a string
- How to remove all leading whitespace in string in Python?
- How to remove leading and trailing whitespace in a MySQL field?
- How to remove all trailing whitespace of string in Python?
- How to remove leading and trailing whitespace from a MySQL field value?
- Python Pandas – Remove leading and trailing whitespace from more than one column
- Trim (Remove leading and trailing spaces) a string in C#
- Trim a string in Java to remove leading and trailing spaces
- Java Program to remove the leading and trailing quotes from a string
- How to remove white spaces (leading and trailing) from string value in MongoDB?
- How to remove all whitespace from String in Java?
- Remove whitespace in Java string.
- How can we eradicate leading and trailing space characters from a string in MySQL?
- Remove Leading Zeros from a String in C#
- Explain how to remove Leading Zeroes from a String in Java