1. Remove spaces
strip()
" xyz ".strip() # returns "xyz"
" xyz ".lstrip() # returns "xyz "
" xyz ".rstrip() # returns " xyz"
" x y z ".replace(' ', '') # returns "xyz"
2. Replacement("space"," ")
Use replace("\n", "") to replace the preceding
The above is the detailed content of Example code for removing spaces and newlines in Python. For more information, please follow other related articles on the PHP Chinese website!