Strip Characters From a Python String - Real Python
Briefly

Strip Characters From a Python String - Real Python
"By default, Python's .strip() method removes whitespace characters from both ends of a string. To remove different characters, you can pass a string as an argument that specifies a set of characters to remove. The .strip() method is useful for tasks like cleaning user input, standardizing filenames, and preparing data for storage. The .strip() method removes leading and trailing whitespace but doesn't remove whitespace from the middle of a string."
"You can use .strip() to remove specified characters from both ends of the string by providing these characters as an argument. With the related methods , you can remove characters from one side of the string only. All three methods, .strip(), .lstrip(), and .rstrip(), remove character sets, not sequences. You can use .removeprefix() and .removesuffix() to strip character sequences from the start or end of a string."
The .strip() method removes leading and trailing whitespace while preserving whitespace in the middle of a string. Passing a string argument to .strip() causes removal of any characters contained in that argument from both ends. Use .lstrip() or .rstrip() to remove characters from only the left or right side, respectively. .strip(), .lstrip(), and .rstrip() operate on character sets rather than fixed sequences. Use .removeprefix() and .removesuffix() when a precise sequence needs removal from the start or end. Common uses include cleaning user input, standardizing filenames, and preparing data for storage.
Read at Realpython
Unable to calculate read time
[
|
]