Strip Methods
Python strings have the strip(), lstrip(), rstrip() methods for removing any character from both ends of a string. If the characters to be removed are not specified then white-space will be removed
strip() #removes from both ends
lstrip() #removes leading characters (Left-strip)
rstrip() #removes trailing characters (Right-strip)
- String Manipulation in Python
- Python String Methods for String Manipulation
- Python Programming – String Functions
Examples
spacious = " xyz " print spacious.strip() spacious = " xyz " print spacious.lstrip() spacious = "xyz " print spacious.rstrip()