Python教程

python完美打印-pprint

本文主要是介绍python完美打印-pprint,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

python完美打印-pprint

注:完美打印,要求被打印的是字典格类型

import pprint


data = {
'this is a string': "hello world!",
'this is a list': "[1, 2, 3, 4]",
'this is a tuples': "(1.0, 2.3, 4.5)"
}

# 普通打印
print(data)
# 输出:
# {'this is a string': 'hello world!', 'this is a list': '[1, 2, 3, 4]', 'this is a tuples': '(1.0, 2.3, 4.5)'}


# 完美打印
pprint.pprint(data)
# 输出:
# {'this is a list': '[1, 2, 3, 4]',
#  'this is a string': 'hello world!',
#  'this is a tuples': '(1.0, 2.3, 4.5)'}
这篇关于python完美打印-pprint的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!