Chapters
Python114 chapters

ReferenceString methods

str.strip()

Removes whitespace, or any of the given characters, from both ends.

Signature

text.strip(chars=None)

Parameters

NameMeans
charsa set of characters to remove; whitespace when omitted

Returns

A new string.

Example

Python
print(repr("  hello  ".strip()))
print("xxhixx".strip("x"))
print("www.example.com".strip("wmoc."))

Output

'hello'
hi
example

See also