str()函数可以实现list,turple,dict到string的转换
eval()函数可以实现将string转换成list,turple,dict
string转换成list
a = "[[1,2], [3,4], [5,6], [7,8], [9,0]]"
print(type(a))
b = eval(a)
print(b)
print(type(b))
输出:
<class 'str'>
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]]
<class 'list'>
string转换成turple
a = "([1,2], [3,4], [5,6], [7,8], [9,0])"
print(type(a))
b = eval(a)
print(b)
print(type(b))
输出:
<class 'str'>
([1, 2], [3, 4], [5, 6], [7, 8], [9, 0])
<class 'tuple'>
string转换成dict
a = "{1: 'a', 2: 'b'}"
print(type(a))
b = eval(a)
print(b)
print(type(b))
输出:
<class 'str'>
{1: 'a', 2: 'b'}
<class 'dict'>