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)
spacious = " xyz " print spacious.strip() spacious = " xyz " print spacious.lstrip() spacious = "xyz " print spacious.rstrip()
Recommended Python Training
For Python training, our top recommendation is DataCamp.