1:strip () method,remove spaces at the beginning or end of a string
>>> a = "a b C"
>>> A.strip ()
' A B C '
2:lstrip () method,remove spaces at the beginning of a string
>>> a = "a b C"
>>> A.lstrip ()
' A B C '
3:rstrip () method,remove whitespace at the end of a string
>>> a = "a b C"
>>> A.rstrip ()
' A B C '
4:replace () method,all spaces can be removed
# Replace is primarily used for string substitution replace (old, new, count)
>>> a = "a b C"
>>> a.replace ("", "" ")
' ABC '
5:join () method +split () method,all spaces can be removed
# join for character string composition pass in a list of strings, split for string splitting can be split by rules
>>> a = "a b C"
>>> B = A.split () # string divided into lists by Space
>>> b [' A ', ' B ', ' C ']
>>> c = "". Join (b) # Generate a new string using an empty string composition list content
>>> c ' ABC '
# Quick Usage
>>> a = "a b C"
>>> "". Join (A.split ())
' ABC '
Summary of methods for removing whitespace from common strings in Python