隐藏页面特效

05 2023 档案

摘要:说明 Iterable、Container和Sized 每个容器都应该继承这三个抽象基类,或者实现兼容的协议。Iterable通过__iter__方法支持迭代, Container通过__contains__方法支持in运算符,Sized通过__len__方法支持len()函数。 Collectio 阅读全文 »
posted @ 2023-05-12 17:44 我在路上回头看 阅读(68) 评论(0) 推荐(0) 编辑
摘要:# 使用场景 ```python 在 Python 中,虚拟子类是一种使用 `collections.abc` 模块中的 `abc.ABCMeta.register()` 方法创建的特殊子类。 虚拟子类允许将一个类注册为抽象基类的子类,即使在实际继承关系中并没有直接的继承关系。 虚拟子类的使用场景如 阅读全文 »
posted @ 2023-05-12 16:51 我在路上回头看 阅读(110) 评论(0) 推荐(0) 编辑
摘要:引入为什么需要TypeVar PEP484的作者希望借助typing模块引入类型提示,不改动语言的其它部分。通过精巧的元编程技术,让类 支持[]运算不成问题。但是方括号内的T变量必须在某处定义,否则要大范围改动python解释器才能让泛型 支持特殊的[]表示法。鉴于此,我们增加了typing.Typ 阅读全文 »
posted @ 2023-05-12 12:17 我在路上回头看 阅读(857) 评论(0) 推荐(1) 编辑
摘要:```python from typing import Optional def show_count(count: int, singular: str, plural: Optional[str] = None) -> str: Optional[str]表示plural的值可以是一个str或 阅读全文 »
posted @ 2023-05-10 23:30 我在路上回头看 阅读(33) 评论(0) 推荐(0) 编辑
摘要:package main import "fmt" type Sex int // 枚举 const ( SexMan Sex = iota SexWoman SexUnkonw ) func (s Sex) String() string{ switch s { case 0: return "男 阅读全文 »
posted @ 2023-05-05 02:07 我在路上回头看 阅读(37) 评论(0) 推荐(0) 编辑
摘要:# 方式1 a = [1,2,3] print(a) # 4551311680 a.extend([4,5]) print(a) # 4551311680 # 方式2 b = [1,2,3] print(b) # 4494299456 b += [4,5,6] print(b) # 44942994 阅读全文 »
posted @ 2023-05-03 23:39 我在路上回头看 阅读(24) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示