Python语言基础
Python语言进阶
Python数据结构

indent 定义缩进量

使用 indent 参数来定义缩进量
以下实例为学习使用 indent 参数来定义缩进量,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
import json
x = {
  "name": "Bill",
  "age": 63,
  "married": True,
  "divorced": False,
  "children": ("Jennifer","Rory","Phoebe"),
  "pets": None,
  "cars": [
    {"model": "Porsche", "mpg": 38.2},
    {"model": "BMW M5", "mpg": 26.9}
  ]
}
# use four indents to make it easier to read the result:
print(json.dumps(x, indent=4))
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com

{

    "name""Bill",

    "age": 63,

    "married": true,

    "divorced"False,

    "children": [

        "Jennifer",

        "Rory",

        "Phoebe"

    ],

    "pets": null,

    "cars": [

        {

            "model""Porsche",

            "mpg": 38.2

        },

        {

            "model": "BMW M5",

            "mpg": 26.9

        }

    ]

}

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4