python去除双引号
时间: 2023-05-16 10:05:08 浏览: 72
可以使用字符串的 replace() 方法,将双引号替换为空字符串。例如:
```
my_string = 'This is a "quoted" string.'
my_string = my_string.replace('"', '')
print(my_string)
```
输出:
```
This is a quoted string.
```
相关问题
python 去掉单引号与双引号
可以使用字符串的 strip() 方法来去掉单引号和双引号,例如:
```python
s = "'hello' \"world\""
s = s.strip("'").strip("\"")
print(s) # 输出结果为:hello world
```
其中,strip() 方法可以去掉字符串开头和结尾的指定字符,默认去掉空格字符。所以上述代码中,先使用 strip() 方法去掉单引号,再使用 strip() 方法去掉双引号。
python 如何去除双引号
在 Python 中,可以使用字符串的 replace() 方法来去除双引号。示例如下:
```python
str_with_quotes = 'This is a "string" with "quotes".'
str_without_quotes = str_with_quotes.replace('"', '')
print(str_without_quotes) # 输出:This is a string with quotes.
```
在上面的代码中,我们首先定义了一个包含双引号的字符串 `str_with_quotes`。然后使用 `replace()` 方法将其中的双引号替换为空字符串,得到了不包含双引号的字符串 `str_without_quotes`。最后输出 `str_without_quotes` 的值,即可看到双引号已经被成功去除了。