Hello ,
Can someone explain to me the difference between print and pprint?
Hello ,
Can someone explain to me the difference between print and pprint?
print
is a built-in function which prints values with very little
additional formatting.
pprint
is a function that has to be imported from the module also
called “pprint”. It tries to “pretty print” values and make them nicer
to look at, usually by printing one item per line.
>>> from pprint import pprint
>>> D = dict(zip(range(1000, 10010), range(20000, 20010)))
>>> print(D)
{1008: 20008, 1009: 20009, 1000: 20000, 1001: 20001, 1002: 20002, 1003: 20003, 1004: 20004, 1005: 20005, 1006: 20006, 1007: 20007}
>>>
>>> pprint(D)
{1000: 20000,
1001: 20001,
1002: 20002,
1003: 20003,
1004: 20004,
1005: 20005,
1006: 20006,
1007: 20007,
1008: 20008,
1009: 20009}
>>>
See the documentation here: