会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
洗洗睡吧
自闭。。。。。。
博客园
首页
新随笔
联系
订阅
管理
上一页
1
···
5
6
7
8
9
10
11
12
13
···
51
下一页
2023年7月11日
自定义参数类型断言装饰器
摘要: # 代码 ```python from inspect import signature from functools import wraps def typeassert(*ty_args, **ty_kwargs): def decorate(func): if not __debug__:
阅读全文
posted @ 2023-07-11 08:57 我在路上回头看
阅读(36)
评论(0)
推荐(0)
2023年7月10日
re.sub参数之回调函数
摘要: ```python from calendar import month_abbr import re def change_date(m): mon_name = month_abbr[int(m.group(1))] return '{} {} {}'.format(m.group(2), mo
阅读全文
posted @ 2023-07-10 08:47 我在路上回头看
阅读(24)
评论(0)
推荐(0)
2023年7月9日
秒杀案例设计
摘要: # 存入redis中的设计 ```python 商品库存 key: sk:prodid:qt string: 剩余个数 秒杀成功者清单 key: sk:prodid:user set: 成功者的user_id 成功者的user_id 成功者的user_id ``` # 代码实现 ```java pu
阅读全文
posted @ 2023-07-09 09:50 我在路上回头看
阅读(26)
评论(0)
推荐(0)
2023年6月25日
typing模块中Protocol协议的使用
摘要: # 说明 ```python 在 Python 的 typing 模块中,Protocol 是一个用于定义协议(Protocol)的类。 协议是一种形式化的接口,定义了一组方法或属性的规范,而不关心具体的实现。Protocol 类提供了一种方式来定义这些协议。 使用 Protocol 类时,可以定义
阅读全文
posted @ 2023-06-25 03:50 我在路上回头看
阅读(2391)
评论(0)
推荐(0)
2023年5月12日
collection.abc模块下的抽象基类UML类图说明
摘要: 说明 Iterable、Container和Sized 每个容器都应该继承这三个抽象基类,或者实现兼容的协议。Iterable通过__iter__方法支持迭代, Container通过__contains__方法支持in运算符,Sized通过__len__方法支持len()函数。 Collectio
阅读全文
posted @ 2023-05-12 17:44 我在路上回头看
阅读(117)
评论(0)
推荐(0)
虚拟子类的使用场景
摘要: # 使用场景 ```python 在 Python 中,虚拟子类是一种使用 `collections.abc` 模块中的 `abc.ABCMeta.register()` 方法创建的特殊子类。 虚拟子类允许将一个类注册为抽象基类的子类,即使在实际继承关系中并没有直接的继承关系。 虚拟子类的使用场景如
阅读全文
posted @ 2023-05-12 16:51 我在路上回头看
阅读(147)
评论(0)
推荐(0)
python中的泛型使用TypeVar
摘要: 引入为什么需要TypeVar PEP484的作者希望借助typing模块引入类型提示,不改动语言的其它部分。通过精巧的元编程技术,让类 支持[]运算不成问题。但是方括号内的T变量必须在某处定义,否则要大范围改动python解释器才能让泛型 支持特殊的[]表示法。鉴于此,我们增加了typing.Typ
阅读全文
posted @ 2023-05-12 12:17 我在路上回头看
阅读(1052)
评论(0)
推荐(1)
2023年5月10日
typing的中的Optional说明
摘要: ```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 我在路上回头看
阅读(41)
评论(0)
推荐(0)
2023年5月5日
枚举
摘要: 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 我在路上回头看
阅读(43)
评论(0)
推荐(0)
2023年5月3日
python中如何使两个序列相加不改变内存地址的几种方式
摘要: # 方式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 我在路上回头看
阅读(31)
评论(0)
推荐(0)
上一页
1
···
5
6
7
8
9
10
11
12
13
···
51
下一页
公告