python去掉字符串中的双引号
时间: 2023-09-01 11:08:58 浏览: 22
要去掉字符串中的双引号,你可以使用字符串的 `replace()` 方法。以下是一个示例代码:
```python
string = '"Hello, World!"'
new_string = string.replace('"', '')
print(new_string)
```
输出结果将是:
```
Hello, World!
```
在这个例子中,我们使用 `replace()` 方法将双引号替换为空字符串,从而去掉了字符串中的双引号。
相关问题
python去除字符串中双引号
可以使用字符串的 replace 方法来去除字符串中的双引号,例如:
```python
s = 'Hello "world"'
s = s.replace('"', '')
print(s) # 输出:Hello world
```
上述代码中,我们先定义了一个字符串 `s`,然后使用 `replace` 方法将其中的双引号替换为空字符串,最后输出结果。
python去除字符串中的双引号
你可以使用字符串的replace()方法来去除字符串中的双引号。下面是一个示例:
```python
str_with_quotes = 'This is a "string" with "double quotes".'
str_without_quotes = str_with_quotes.replace('"', '')
print(str_without_quotes)
```
输出结果将是:
```
This is a string with double quotes.
```
这样就去除了字符串中的双引号。