Python .strip method not working -
i have function begins this:
def solve_eq(string1): string1.strip(' ') return string1
i'm inputting string '1 + 2 * 3 ** 4' return statement not stripping spaces @ , can't figure out why. i've tried .replace() no luck.
strip not remove whitespace everywhere, @ beginning , end. try this:
def solve_eq(string1): return string1.replace(' ','')
using strip()
in case redundant (obviously, commentators!).
p.s. bonus helpful snippet before take break (thanks op!):
import re a_string = re.sub(' +', ' ', a_string).strip()
Comments
Post a Comment