String Methods
str.strip()
Remove consecutive characters from both ends until a character outside the allowed set is reached. With None or omitted chars, remove Python-defined whitespace. An explicit chars string supplies individual code points, not an exact prefix or suffix. Internal characters are retained. The original string is unchanged.
Formal Syntax & Structure
python syntaxpython
text.strip(chars=None, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| chars | str | None | Characters eligible for removal; None means whitespace. |
Return Value
str
Trimmed text.
Working Example
Example Snippetpython
print(repr("!!name!!".strip("!")))print(repr(" x ".strip()))