摘要: import random class RandomGenerator: def __init__(self,count=10,minimum=1,maximum=100): self.count=count self.min=minimum self.max=maximum self.g=self 阅读全文
posted @ 2020-10-02 23:12 ascertain 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 在其他面向对象的高级语言中,都有重载的概念 重载: 同一个方法名,但是参数的数量和类型不一样,就是同一个方法的重载 Python没有重载 Python不需要重载 Python中,方法(函数)定义中,形参非常灵活,不需要指定类型(就是指定了,也只是一个说明,而非约束),参数个数也不固定(可变参数),一 阅读全文
posted @ 2020-10-02 21:56 ascertain 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 类中可以定义__del__方法,称为析构方法 作用: 销毁类的实例时调用,以释放占用的资源 由于python实现了垃圾回收机制,这个方法不确定何时执行,有必要时,使用del语句手动删除实例 class Person: def __init__(self,name,age=20): self.name 阅读全文
posted @ 2020-10-02 19:06 ascertain 阅读(169) 评论(0) 推荐(0) 编辑
摘要: property装饰器: 后面跟的函数名就是以后的属性,它即是getter,这个必须有,只读属性 setter装饰器: 于属性名同名,接收两个参数,第一个是self,第二个是将要赋值的值,将属性变为可写 deleter装饰器: 可以控制属性是否删除 property装饰器必须在前,setter,de 阅读全文
posted @ 2020-10-02 18:55 ascertain 阅读(809) 评论(0) 推荐(0) 编辑
摘要: lambda <args>:<expression> <expression>必须是单个表达式,不能是多个由;分割的表达式 使用exec函数 b=1 p=lambda v:exec("global b;b+=1;print(v+b)") print(p(1)) print(p(2)) 此种方式返回值 阅读全文
posted @ 2020-10-02 18:08 ascertain 阅读(3457) 评论(0) 推荐(0) 编辑
摘要: relevance.py from relevance1 import Mim from relevance2 import get p=Mim(22,33,44) print(p.get()) def monkeypath4Mim(): Mim.get=get if __name__ == '__ 阅读全文
posted @ 2020-10-02 13:10 ascertain 阅读(109) 评论(0) 推荐(0) 编辑
摘要: from pathlib import Path def openfile(path:str)->None: yield path def cix(path:str): p=Path(path) if p.exists(): if p.is_file(): yield from openfile(s 阅读全文
posted @ 2020-10-02 12:50 ascertain 阅读(192) 评论(0) 推荐(0) 编辑
摘要: from pathlib import Path import argparse,sys,datetime,stat,platform def showdir(path:str='.',all=False,detail=False,human=False,reverse=False): def co 阅读全文
posted @ 2020-10-02 11:25 ascertain 阅读(225) 评论(0) 推荐(0) 编辑
摘要: class Mse: @classmethod def __new__(cls,*args,**kwargs): pass @classmethod def class_method(cls): print('class={0.__name__} ({0})'.format(cls)) cls.HE 阅读全文
posted @ 2020-10-02 11:22 ascertain 阅读(132) 评论(0) 推荐(0) 编辑