> For the complete documentation index, see [llms.txt](https://imhuay.gitbook.io/studies/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://imhuay.gitbook.io/studies/notes/_archives/2022/08/python-rong-qi-ji-lei-de-shi-yong.md).

# Python 容器基类的使用

![last modify](https://img.shields.io/static/v1?label=last%20modify\&message=2022-10-13%2001%3A56%3A19\&color=yellowgreen\&style=flat-square)

容器基类列表：[collections.abc — Python 文档](https://docs.python.org/zh-cn/3/library/collections.abc.html)

## 使用场景

### Type Hints

```python
# def foo(ls: Union[List, Tuple]):
def foo(ls: Sequence):
    ...
```

### 判断一个具体类或实例是否具有某一特定的接口

```python
from typing import *

# 判断能否 len(obj)，即判断是否实现了 __len__
isinstance(obj, Sized)

# 判断能否 obj[index]
isinstance(obj, Sequence)

# 判断某个类是否可以哈希
issubclass(cls, Hashable)
```


---

# 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:

```
GET https://imhuay.gitbook.io/studies/notes/_archives/2022/08/python-rong-qi-ji-lei-de-shi-yong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
