Stripping whitespace from a string. : String strip « String « Python






Stripping whitespace from a string.

Stripping whitespace from a string.
string1 = "\t  \n  This is a test string. \t\t \n"

print 'Original string: "%s"\n' % string1
print 'Using strip: "%s"\n' % string1.strip()
print 'Using left strip: "%s"\n' % string1.lstrip()
print 'Using right strip: "%s"\n' % string1.rstrip()

           
       








Related examples in the same category