随笔分类 - python
摘要:# 1.自定义异常类, 继承Exception, 魔法方法有init和str(设置异常描述信息)class ShortInputError(Exception): def __init__(self, length, min_len): # 用户输入的密码长度 self.length = lengt
阅读全文
摘要:# 在python中,获取和修改私有属性值# 一般定义函数名get_xx set_xx用来修改私有属性值class Master(object): def __init__(self): self.kongfu = '[师父方法]' def cake(self): print(f'运用{self.k
阅读全文
摘要:class Master(object): def __init__(self): self.kongfu = '[师父方法]' def cake(self): print(f'运用{self.kongfu}来实现')class School(Master): def __init__(self):
阅读全文
摘要:class Master(object): def __init__(self): self.kongfu = '[师父方法]' def make_cake(self): print(f'运用{self.kongfu}来实现')class School(object): def __init__(s
阅读全文
摘要:# 1. 师父类, 属性和方法class Master(object): def __init__(self): self.kongfu = '[古法煎饼果子配方]' def make_cake(self): print(f'运用{self.kongfu}制作煎饼果子')# 为了验证多继承,添加Sc
阅读全文
摘要:class Furniture(): def __init__(self, name, area): self.name = name self.area = areaclass Home(): def __init__(self, address, area): # 地理位置 self.addre
阅读全文
摘要:_str_() : 当使用print输出对象的时候,默认打印对象的内存地址。如果类定义了_str_方法,那么就会打印从在这个方法中return的数据。 _del_() : 当删除对象时,python解释器也会默认调用_del_()方法。
阅读全文
摘要:# 1. 定义类: 初始化属性、 被烤和添加调料的方法、显示对象信息的strclass SweetPotato(): def __init__(self): # 被烤的时间 self.cook_time = 0 # 烤的状态 self.cook_state = '生的' # 调料列表 self.co
阅读全文
摘要:# 1.定义类: 带参数的init:宽度和高度; 实例方法:调用实例属性class Washer(): def __init__(self, width, height): self.width = width self.height = height def print_info(self): p
阅读全文
摘要:# 目标: 定义init魔法方法设置初始化属性,并访问调用# _init_()方法的作用:初始化对象。"""1. 定义类 init魔法方法: width 和 height 添加实例方法:访问实例属性2.创建对象3.验证成果 调用实例方法"""class Washer(): def __init__(
阅读全文
摘要:# 1.用户输入目标文件 sound.txt.mp3old_name = input('请输入您需要备份的文件名: ')# print(old_name)# print(type(old_name))# 2. 规划备份文件的名字# 2.1 提取后缀 -- 找到名字中的点 -- 名字和后缀分离--最右
阅读全文