作者:HK12593 | 来源:互联网 | 2023-09-23 21:01
a="{'name':'idoxu','sex':'male','age':30}"
b=eval(a) #eval函数能把字符串转为字典?
print(b)
print(type(b))c="{'name':'idoxu','sex':'male','age':30}"
exec(c)#exec函数能把字符串转为字典 但是为什么转弯后还是str?
print(c)
print(type(c))d={'name':'idoxu','sex':'male','age':30}
for key,value in d.items():print("\"%s\":\"%s\"" % (key, value))
D:\学习\Python工程\venv\Scripts\python.exe D:/学习/Python工程/practice/test_demo.py
{'name': 'idoxu', 'sex': 'male', 'age': 30}
{'name':'idoxu','sex':'male','age':30}
"name":"idoxu"
"sex":"male"
"age":"30"Process finished with exit code 0