Python dict 转 str 可以使用 json 模块的 mps() 函数来实现,具体代码如下:输出结果:
Python dict 转 str 可以使用 json 模块的 dumps() 函数来实现,具体代码如下:
import json
# 定义一个字典
dict1 = {'name': 'Bob', 'age': 20, 'gender': 'male'}
# 将字典转换为字符串
str1 = json.dumps(dict1)
print(str1)
输出结果:
{"name": "Bob", "age": 20, "gender": "male"}
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(6条)