python - Removing strings from other strings -
how remove part of string like
blue = 'blue ' yellow = 'yellow' words = blue + yellow if blue in words: words = words - yellow that thought like?
edit: know thatit won't work want know work. since cant use '-' in str()
you can use str.replace exchange text empty string:
words = words.replace(yellow,'') note transform:
"the yellow herring" into simply:
"the herring" (the replacement happen anywhere in string). if want remove 'yellow' end of string, use .endswith , slice:
if blue in words , words.endswith(yellow): words = words[:-len(yellow)]
Comments
Post a Comment