python – Why doesnt .strip() remove whitespaces?
python – Why doesnt .strip() remove whitespaces?
strip
does not remove whitespace everywhere, only at the beginning and end. Try this:
def solve_eq(string1):
return string1.replace( , )
This can also be achieved using regex:
import re
a_string = re.sub( +, , a_string)
strip
doesnt change the original string since strings are immutable. Also, instead of string1.strip( )
, use string1.replace( , )
and set a return value to the new string or just return it.
Option 1:
def solve_eq(string1):
string1 = string1.replace( , )
return string1
Option 2:
def solve_eq(string1):
return string1.replace( , )
python – Why doesnt .strip() remove whitespaces?
strip
returns the stripped string; it does not modify the original string.