摘要: # Python 3.5 之后可用,之前需要pip安装 from typing import TypedDict # 每个字段必须 class Person(TypedDict): name: str age: int qq: str p1_dict: Person = { "name": "大佬" 阅读全文
posted @ 2023-11-28 21:01 zwnsyw 阅读(91) 评论(0) 推荐(0) 编辑
摘要: import threading import time def singleton(cls): instances = {} def get_instance(*args, **kwargs): # 判断实例是否已经存在 if cls not in instances: # 如果不存在,创建新的实 阅读全文
posted @ 2023-11-28 20:13 zwnsyw 阅读(25) 评论(0) 推荐(0) 编辑
摘要: # 定义接口类 from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def speak(self): pass # 定义实现类 class Dog(Animal): def speak(self): retur 阅读全文
posted @ 2023-11-28 15:44 zwnsyw 阅读(42) 评论(0) 推荐(0) 编辑