eval函数就是实现str与list、dict、tuple之间的转化
栗子:
a = "[[1,2], [3,4], [5,6], [7,8], [9,0]]" aa = eval(a) print(type(a)) print(type(aa)) b = "{1: 'a', 2: 'b'}" bb = eval(b) print(type(b)) print(type(bb)) c = "([1,2], [3,4], [5,6], [7,8], (9,0))" cc = eval(c) print(type(c)) print(type(cc)) d = "3+5" dd = eval(d) print(dd) 输出结果: <class 'str'> <class 'list'> <class 'str'> <class 'dict'> <class 'str'> <class 'tuple'> 8