栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python小技巧—真别说,用print()让字典输出更易阅读

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python小技巧—真别说,用print()让字典输出更易阅读

在Python中使用 Print() 函数,有时候的输出贼拉的丑陋,此时我们使用 pprint 可以使输出更加美观,一起来看看是怎么做到的吧

from pprint import pprint


data = {


    "name": "john deo",


    "age": "22",


    "address": {"contry": "canada", "state": "an state of canada :)", "address": "street st.34 north 12"},


    "attr": {"verified": True, "emialaddress": True},


}


print(data)


pprint(data)

输出如下:

{'name': 'john deo', 'age': '22', 'address': {'contry': 'canada', 'state': 'an state of canada :)', 'address': 'street st.34 north 12'}, 'attr': {'verified': True, 'emialaddress': True}}


{'address': {'address': 'street st.34 north 12',


             'contry': 'canada',


             'state': 'an state of canada :)'},


 'age': '22',


 'attr': {'emialaddress': True, 'verified': True},


 'name': 'john deo'}

可见使用 pprint 函数可以让字典的输出更加容易阅读。

好了,今天的分享就到这里,希望对大家有所帮助。

对于Python有兴趣想一起交流的,都可以加下微信,在这里我也准备了一份学习资料送给大家,主要包含爬虫入门(爬虫工作流程  http工作流程)、逆向工程、逆向算法、异步爬虫、安卓逆向这几个板块。(截图为部分展示)

 

适合Python入门的朋友学习,都是精华,快来白嫖!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/844242.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号