The strip()
method removes characters from both left and right based on the argument (a string specifying the set of characters to be removed).
string.strip(chars)
If the chars argument is not provided, all leading and trailing whitespaces are removed from the string.
The strip() returns a copy of the string with both leading and trailing characters stripped.
string = ' xoxo love xoxo '# Leading and trailing whitespaces are removedprint(string.strip())# All <whitespace>,x,o,e characters in the left# and right of string are removedprint(string.strip(' xoe'))# Argument doesn't contain space# No characters are removed.print(string.strip('stx'))string = 'android is awesome'print(string.strip('an'))
chars
argument, it stops removing the leading characters.chars
argument, it stops removing the trailing characters.**********END OF ARTICLE **********
Comments