LoginSignup
0
1

More than 3 years have passed since last update.

pprintとjson.dumps

Last updated at Posted at 2020-06-21
import json
import pprint

l = ['apple', 'orange', 'banana', 'peach', 'mango']
l.insert(0,l[:])
#l.insert(0,l[:])
#l.insert(0,l[:])
#l.insert(0,l[:])
#print(l)
pp = pprint.PrettyPrinter(indent=4, width=40, compact=True, depth=3)
pp.pprint(l)


d = {'a': 'A','b': 'B', 'c': {'x': {'y': 'Y'}}}
pp = pprint.PrettyPrinter(indent=4, width=40)
pp.pprint(d)


print(json.dumps(d, indent=4))

実行結果:

[   [   'apple', 'orange', 'banana',
        'peach', 'mango'],
    'apple', 'orange', 'banana',
    'peach', 'mango']
{   'a': 'A',
    'b': 'B',
    'c': {'x': {'y': 'Y'}}}
{
    "a": "A",
    "b": "B",
    "c": {
        "x": {
            "y": "Y"
        }
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1