How do I strip all the spaces in a python string? For example, I want a string like strip my spaces
to be turned into stripmyspaces
, but I cannot s
string1=" This is Test String to strip leading space"
print string1
print string1.lstrip()
string2="This is Test String to strip trailing space "
print string2
print string2.rstrip()
string3=" This is Test String to strip leading and trailing space "
print string3
print string3.strip()
string4=" This is Test String to test all the spaces "
print string4
print string4.replace(" ", "")