标签: python
我有一个字符串str="[0,1,12]"
str="[0,1,12]"
最有效的方法是删除"[","]"和",",只留下数字为list?我尝试了.rstrip(),但它只接受字符串末尾的字符。
"["
"]"
","
list
.rstrip()
答案 0 :(得分:6)
将字符串评估为list:
from ast import literal_eval numbers = literal_eval(your_string)