eval内置函数
1.字符串转换成列表
a = "[[1,2],[3,4]]"
print(type(a))
b = eval(a)
c = list(a)
print(type(b))
print(type(c))
print(b)
print(c)
2.字符串转换成字典
a = "{1:'a',2:'b'}"
print(type(a))
b = dict(eval(a))
print(type(b))
print(b)
3.字符串转换称元组
a='([1,2],[3,4])'
print(type(a))
b = eval(a)
print(b)
来源:CSDN
作者:_nigar
链接:https://blog.csdn.net/nigar_/article/details/104116568