eval函数把字符串转化为list、dict、tuple
str函数把list,dict,tuple转为字符串
# 字符串转换成列表
a = “[[1,2], [3,4], [5,6], [7,8], [9,0]]”
print(type(a))
b = eval(a)
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)
#列表转字符串
a=[1,2,3]
print(type(a))
b=str(a)
print(type(b))
#字典转字符串
dict={‘a’:12,‘b’:34}
print(type(dict))
b=str(dict)
print(type(b))
#元组转字符串
a=((1,2),(3,4))
print(type(a))
b=str(a)
print(type(b))