tem*_*ame 2 python pretty-print python-3.x
matrix = [ [1,2,3], [4,5,6], [7,8,9] ]
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(matrix)
Run Code Online (Sandbox Code Playgroud)
这不是很好的印刷品.它打印丑陋.
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Run Code Online (Sandbox Code Playgroud)
是什么赋予了??
小智 5
这是因为在一行上打印数组的长度小于默认值width80.您可能需要查看文档pprint.
例如,如果我们这样做:
matrix = [ [1,2,3], [4,5,6], [7,8,9] ]
import pprint
pp = pprint.PrettyPrinter(indent=4,width=20)
pp.pprint(matrix)
Run Code Online (Sandbox Code Playgroud)
我们得到:
[ [1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2816 次 |
| 最近记录: |