在Python中,去除字符串两端的引号可以通过以下几种方法实现:
1. 使用 `strip()` 方法:
s = '"hello"'s_no_quotes = s.strip('"')print(s_no_quotes) 输出:hello
2. 使用切片操作:
s = '"hello"'s_no_quotes = s[1:-1]print(s_no_quotes) 输出:hello

3. 使用 `replace()` 方法:
s = '"hello"'s_no_quotes = s.replace('"', '')print(s_no_quotes) 输出:hello
4. 使用正则表达式(`re.sub()`):
import res = '"hello"'s_no_quotes = re.sub('"', '', s)print(s_no_quotes) 输出:hello
以上方法都可以用来去除字符串两端的引号。选择哪种方法取决于你的具体需求和代码的上下文
