python How can I strip first and last double quotes
问题 I want to strip double quotes from string = '"" " " ""\\1" " "" ""' to become string = '" " " ""\\1" " "" "' I tried to use rstrip , lstrip and strip('[^\"]|[\"$]') but it did not work. How can I do this? Thank you for helping me. 回答1: If the quotes you want to strip are always going to be "first and last" as you said, then you could simply use: string = string[1:-1] 回答2: If you can't assume that all the strings you process have double quotes you can use something like this: if string