自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(9)
  • 收藏
  • 关注

原创 python : 可变变量作为函数参数

>>> def add_one( L = [] ):... L.append(1)... return L...>>> a = add_one()>>> b = add_one(list(range(5)))>>> c = add_one() + list(range(5))>>> len(b...

2019-03-19 09:47:39 618

转载 python :惰性计算

python中含有惰性计算,即调用的时候才开始计算https://www.cnblogs.com/shiqi17/p/9608195.html>>> f_list = [lambda x: x**i for i in range(5)]>>> sum((f_list[j](10) for j in range(5)))输出为50000...

2019-03-19 09:17:49 911

转载 python : property

Property的设计初衷:【引以为戒:考虑计算成本,考虑使用方代码不更改,初次见代码心有感慨,道路长漫漫,我辈须努力】代码复用延迟计算更加规范的对象属性访问管理class X: def __init__(self, w, h): self.w = w self.h = h self.BMI = w / h ** 2 ...

2019-03-12 16:23:12 165

转载 python : attribute access

Attribute相关的操作一一般有:CreateReadUpdateDeleteclass X: pass if __name__ == "__main__": # print(X.a) X.a = "a" print(X.a) X.a = "aa" print(X.a) del X.a # print(X....

2019-03-12 16:03:26 213

转载 python : special method

class X: passclass Y: """Class Y""" def __str__(self): return "{} object".format(self.__class__.__name__) def __len__(self): return 10 def __bool__(self): ...

2019-03-12 16:00:32 352

转载 python : 属性封装

class Model: __name = "DNN" def __init__(self, name): self.__name = name def print_name(self): print(self.__name) @classmethod def print_cls_name(cls): pr...

2019-03-12 15:32:05 596

转载 类方法

class Model: name = "DNN" def __init__(self, name): self.name = name def print_name(self): print(self.name) @classmethod def print_cls_name(cls): print(cls...

2019-03-12 15:26:47 94

原创 Python: 装饰器

直接上程序:def decorate(func): func.__doc__ += '\nDecorate by decorater.' return funcdef add(x, y): 'Return the sum of x and y.' return x + yadd = decorate(add)如上,我们需要在add函数的帮助文档...

2019-03-02 16:45:10 110

转载 Python: 闭包

def make_averager():count = 0total = 0def averager(new_value):nonlocal count, totalcount += 1total += new_valuereturn total / countreturn averager>>> from test import make_averager&g...

2019-03-01 21:48:52 78

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除