""" 模块:python3 strToDict.py 功能:python3 字符串、字典之间的转换。 说明:字典和普通字符串之间的转换。 """ # 1.dict -> pythonStr d1 = {"a": 1, "b": 2} str1 = str(d1) print("str1:", str1, type(str1)) # str1: {'a': 1, 'b': 2} <class 'str'> # 2.pythonStr -> dict d1 = eval(str1) print("d1:", d1, type(d1)) # d1: {'a': 1, 'b': 2} <class 'dict'>
python3 strToDict.py
