Is there a Python function that will trim whitespace (spaces and tabs) from a string?
Example: \t example string\t
→ example string
Is there a Python function that will trim whitespace (spaces and tabs) from a string?
Example: \t example string\t
→ example string
For leading and trailing whitespace:
Otherwise, a regular expression works:
for removing whitespaces from the middle of the string
output: ATGCGACACGATCGACC
You can also use very simple, and basic function: str.replace(), works with the whitespaces and tabs:
Simple and easy.
try translate
Generally, I am using the following method:
Note: This is only for removing "\n", "\r" and "\t" only. It does not remove extra spaces.