Good job! Sometimes, we want to get rid of certain characters (such as white spaces) at the beginning or end of a string. Python has some built-in functions for that purpose:
dirty_string = ' I probably like white spaces too much. '
If you call
strip() without an argument, it will remove all white spaces from the string by default. You can also specify another character or substring to strip:
dirty_string = ',,,,I probably like commas too much.,,,'
In the second example, we remove the commas instead of the spaces.
There are two similar functions:
lstrip() removes characters from the beginning only, and
rstrip() removes characters from the end only.