string转换list<string>
时间: 2023-09-21 08:09:21 浏览: 94
要将字符串转换为列表,可以使用split()方法将字符串拆分为多个元素,然后将这些元素添加到列表中。下面是一个示例代码:
```python
string = "1,2,3,4,5"
list = string.split(",")
print(list)
```
输出结果为:\['1', '2', '3', '4', '5'\]
在这个示例中,我们使用split(",")方法将字符串按逗号分隔成多个元素,并将这些元素添加到列表中。你可以根据需要修改分隔符。
#### 引用[.reference_title]
- *1* [python中list与string的转换](https://blog.csdn.net/bufengzj/article/details/90231555)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [String[]和List<String>的区别及相互转换](https://blog.csdn.net/qq_33774822/article/details/83188727)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文