python去掉数组中的数值双引号
时间: 2023-08-11 22:04:28 浏览: 487
在Python中,可以使用`strip()`方法去掉字符串两侧的引号。如果要去掉数组中每个元素值的双引号,可以使用列表推导式来实现。以下是一个示例代码:
```python
# 带有双引号的字符串数组
array = ['"value1"', '"value2"', '"value3"']
# 去掉数组中每个元素值的双引号
array_without_quotes = [value.strip('"') for value in array]
# 打印结果
print(array_without_quotes)
```
在上面的代码中,我们定义了一个带有双引号的字符串数组`array`。然后,使用列表推导式`[value.strip('"') for value in array]`,遍历数组中的每个元素,使用`strip('"')`方法去掉每个元素值的双引号。最后,将处理后的结果存储在`array_without_quotes`列表中。
运行上述代码后,将得到一个不带双引号的数组`array_without_quotes`。输出结果为:`['value1', 'value2', 'value3']`。
这样,你就可以在数组中去掉每个元素值的双引号了。
阅读全文
相关推荐












