I wanted to remove all occurrences of single and double apostrophes in lots of strings.
I tried this-
mystring = "this string shouldn't have any apostrophe - \' or \" at all"
print(mystring)
mystring.replace("'","")
mystring.replace("\"","")
print(mystring)
It doesn't work though! Am I missing something?
Replace is not an in-place method, meaning it returns a value that you must reassign.
mystring = mystring.replace("'", "")
mystring = mystring.replace('"', "")
In addition, you can avoid escape sequences by using single and double quotes like so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With