PythonStringstrip

Removes leading and trailing whitespace (or specified characters).

Syntax

str.strip(chars?)

Example

Enter values below to update the example in real time.

print
strip
text = "  hello world  "
print(text.strip())   # "hello world"
print("***hi***".strip("*"))  # "hi"