如何在 Python 中“很好地"打印列表 [英] How to print a list in Python "nicely"

查看:33
本文介绍了如何在 Python 中“很好地"打印列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PHP 中,我可以这样做:

echo '

'print_r($array);echo '</pre>'

在 Python 中,我目前只是这样做:

打印the_list

然而,这将导致大量数据.有没有办法将它很好地打印成可读的树?(有缩进)?

解决方案

from pprint import pprintpprint(the_list)

In PHP, I can do this:

echo '<pre>'
print_r($array);
echo '</pre>'

In Python, I currently just do this:

print the_list

However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)?

解决方案

from pprint import pprint
pprint(the_list)

这篇关于如何在 Python 中“很好地"打印列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆