eval函数就是实现list、dict、tuple与str之间的转化str函数把list,dict,tuple转为为字符串一、字符串转换成列表
a = "[[1,2], [3,4], [5,6], [7,8], [9,0]]" print(type(a)) b = eval(a)print(type(b)) print(b)
二、字符串转换成字典
a = "{1: ‘a‘, 2: ‘b‘}" print(type(a)) b = eval(a) print(type(b)) print(b)
三、字符串转换成元组
a = "([1,2], [3,4], [5,6], [7,8], (9,0))" print(type(a)) b=eval(a) print(type(b)) print(b)
原文地址:https://www.cnblogs.com/sui776265233/p/9900709.html
时间: 2024-10-20 19:17:04