pprint for pretty print

Using pprint

pprint module offers more sophisticated control over printing.

The ''pretty printer'' adds line breaks and indentation to more clearly reveal data structure:


import pprint# ww  w . j  av  a2s .  co m
t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',
      'yellow'], 'blue']]]
    
print pprint.pprint(t, width=30)

The code above generates the following result.





















Home »
  Python »
    Language Basics »




Python Basics
Operator
Statements
Function Definition
Class
Buildin Functions
Buildin Modules