python dict, list 转字符串

在Python中,可以直接使用 内置函数 str(),将字典/列表 转换为 json 字符串

    dicta = {"name":"henry","age":32}
    lista = ["aa","bb","cc","dd"]
    listb = [1,2,3,4,5,6,7,100,200,30,40]

    a1 = str(dicta)
    a2 = str(lista)
    a3 = str(listb)

    print("dicta:",str(dicta))
    print("dicta22:",dicta)
    print("lista:", str(lista))
    print("lista22:",lista)
    print("listb:", str(listb))
    print("listb222:", listb)

 

 

 

  

 

posted @ 2023-04-12 11:00  He_LiangLiang  阅读(67)  评论(0编辑  收藏  举报