You can use the strip()
method to remove trailing and leading spaces:
>>> s=" abd cde "
>>> s.strip()
'abd cde'
Note: the internal spaces are preserved.
More Related Contents:
- How do I lowercase a string in Python?
- Pythonic way to create a long multi-line string
- Random string generation with upper case letters and digits
- About the changing id of an immutable string
- String replace doesn’t appear to be working
- How to split the definition of a long string over multiple lines?
- Check if a word is in a string in Python
- Find and replace string values in list
- pandas dataframe str.contains() AND operation
- Add Leading Zeros to Strings in Pandas Dataframe
- Standard way to embed version into Python package?
- How to insert a character after every 2 characters in a string
- python: SyntaxError: EOL while scanning string literal
- Python convert tuple to string
- How do I remove leading whitespace in Python?
- Python Replace \\ with \ [duplicate]
- Splitting a string with repeated characters into a list
- Finding subsequence (nonconsecutive)
- Mass string replace in python?
- Why is variable1 += variable2 much faster than variable1 = variable1 + variable2?
- How can I split a string of a mathematical expressions in python?
- Why do numbers in a string become “x0n” when a backslash precedes them?
- can only concatenate str (not “bytes”) to str
- When to use %r instead of %s in Python? [duplicate]
- Search for string allowing for one mismatch in any location of the string
- Validating user input strings in Python
- Convert string into Date type on Python [duplicate]
- How to use str.contains() with multiple expressions in pandas dataframes
- How to merge two json string in Python?
- How does str(list) work?