Python3 dict和str互转
2022/8/23 1:55:10
本文主要是介绍Python3 dict和str互转,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# 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'> '''
这篇关于Python3 dict和str互转的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-13python项目部署
- 2025-01-03用FastAPI掌握Python异步IO:轻松实现高并发网络请求处理
- 2025-01-02封装学习:Python面向对象编程基础教程
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门