在Python中,去掉字符串中的引号可以通过以下几种方法实现:
1. 使用 `strip()` 方法去掉字符串两边的引号:
string = '"Hello, World!"'
new_string = string.strip('"')
print(new_string) 输出:Hello, World!
2. 使用切片去掉字符串的引号:
string = '"Hello, World!"'
new_string = string[1:-1]
print(new_string) 输出:Hello, World!
3. 使用 `replace()` 方法将引号替换为空字符串:
string = '"Hello, World!"'
new_string = string.replace('"', '')
print(new_string) 输出:Hello, World!