# Python3 dict和str互转 import ast str_of_dict = "{'key1': 'key1value111', 'key2': 'key2value222'}" newdict = ast.literal_eval(str_of_dict) print(type(str_of_dict)) print(type(newdict)) my_dict = {'key1': 'key1value333', 'key2': 'key2value444'} print(type(my_dict)) print(str(my_dict)) print(type(str(my_dict))) ''' 打印输出内容如下: <class 'str'> <class 'dict'> <class 'dict'> {'key1': 'key1value333', 'key2': 'key2value444'} <class 'str'> '''
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/281621.html