python将字符串类型list转换成list

时间:2022-01-27 01:14:51

python读取了一个list是字符串形式的'[11.23,23.34]',想转换成list类型:

import ast

str_list = "[11.23,23.34]"
list_list = ast.literal_eval(str_list)
print(type(list_list))

 

得到结果为:

<class 'list'>

 

方式二:

import json

str_list = "[11.23,23.34]"
list_list = json.loads(str_list)
print(type(list_list))

得到结果为:

<class 'list'>