SyntaxStudy
Sign Up
Home Python Reference strip() / lstrip() / rstrip()

strip() / lstrip() / rstrip()

method

Remove leading and trailing whitespace (or specified characters) from a string.

Syntax

str.strip(chars=None)

Example

python
'  hello  '.strip()     # 'hello'
'  hello  '.lstrip()    # 'hello  '
'  hello  '.rstrip()    # '  hello'
'***hello***'.strip('*') # 'hello'

# Clean user input
email = input('Email: ').strip().lower()