strip
only removes characters from the beginning and end of a string. You want to use replace
:
str2 = str.replace("\n", "")
re.sub('\s{2,}', ' ', str) # To remove more than one space
More Related Contents:
- Print “\n” or newline characters as part of the output on terminal
- Empty string python zapier
- How do I concatenate items in a list to a single string?
- Fast punctuation removal with pandas
- Converting integer to string in Python
- Checking whether a string starts with XXXX
- Stripping non printable characters from a string in python
- How can I check if character in a string is a letter? (Python)
- Writing a list to a file with Python, with newlines
- How can I convert each item in the list to string, for the purpose of joining them? [duplicate]
- Python __str__ versus __unicode__
- Get last “column” after .str.split() operation on column in pandas DataFrame
- How can I tell if a string repeats itself in Python?
- str.strip() strange behavior
- How do I change the string representation of a Python class? [duplicate]
- Left justify string values in a pandas DataFrame
- Python – How can I pad a string with spaces from the right and left?
- Replace special characters in a string in Python
- Split string by count of characters
- convert a string which is a list into a proper list python
- How can I put an actual backslash in a string literal (not use it for an escape sequence)?
- How do I reverse a string in Python?
- How can I use f-string with a variable, not with a string literal?
- Using Python’s Format Specification Mini-Language to align floats
- How to write multiple strings in one line?
- f.read coming up empty
- 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?
- Why are str.count(”) and len(str) giving different outputs when used on an empty string?