在Python中,去除字符串两端的引号可以通过以下几种方法实现:
1. 使用 `strip()` 方法:
```python
s = '"hello"'
s_no_quotes = s.strip('"')
print(s_no_quotes) 输出:hello
2. 使用切片操作:
```python
s = '"hello"'
s_no_quotes = s[1:-1]
print(s_no_quotes) 输出:hello
3. 使用 `replace()` 方法:
```python
s = '"hello"'
s_no_quotes = s.replace('"', '')
print(s_no_quotes) 输出:hello
4. 使用正则表达式(`re.sub()`):
```python
import re
s = '"hello"'
s_no_quotes = re.sub('"', '', s)
print(s_no_quotes) 输出:hello
以上方法都可以用来去除字符串两端的引号。选择哪种方法取决于你的具体需求和代码的上下文