> For the complete documentation index, see [llms.txt](https://m0uk4.gitbook.io/notebooks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://m0uk4.gitbook.io/notebooks/mouka/python/python-tricks/da-yin-python-zi-dian.md).

# 打印Python字典

**标准字典打印方法有时候难以阅读（单行表达）**

```python
>>> my_mapping = {'a': 23, 'b': 42, 'c': 0xc0ffee}
>>> my_mapping
{'b': 42, 'c': 12648430. 'a': 23}
```

{% hint style="info" %}
**"json" 模块可以以另一种方式打印字典**
{% endhint %}

```python
>>> import json

>>> json_dict = json.dumps(
    my_mapping,    # 将字典转化为 json 格式
    indent=4,    # 设置缩进为 4
    sort_keys=True)    # 以 key 排序
>>> print()
{
    "a": 23,
    "b": 42,
    "c": 12648430
}

# 注意该方法只适用于 key 为原子类型（str,int ...)的字典
>>> json.dumps({all: 'yup'})
TypeError: keys must be a string
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://m0uk4.gitbook.io/notebooks/mouka/python/python-tricks/da-yin-python-zi-dian.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
