4.1.8 Trimming Whitespace: strip()

Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Clean unwanted padding and linebreaks from input data
raw_token = "   auth_token_984712\n\t"
currency_string = "$$450.00$$"

# 1. Strip all leading and trailing whitespace
clean_token = raw_token.strip()

# 2. Strip specific characters like dollar signs '
      
      
    
clean_amount = currency_string.strip("$") print("Clean Token:", clean_token) print("Clean Amount:", clean_amount)
Open in Live Interactive Python Sandbox →