#多态:指出了对象通过共同的属性和动作来操作即访问们不需要考虑他们具体的类 #类就相当于工厂,产生一个个的实例 #不同的对象调用相同的方法,多态是继承的一种体现方式 #斐波那契数列,1 1 2 3 5 8.。。前2个数的和 class Fib: def __init__(self): self._a... ...
分类:
其他好文 时间:
2018-05-20 18:11:54
阅读次数:
172
一 CBV源码流程 urls.py view.py 1)从上面的urls.py文件种可以看到,一个url对应了一个 这个views.OrderView.as_view()函数,并执行这个函数,也就是我们调用order的url会views.OrderView.as_view()() 2)从views. ...
异常处理方法一般为: 可以用 raise 抛出一个异常,以下是一个输入字符太短的异常例子: 如果输入字符长度小于3,那么将会抛出 ShortInputException 异常: 注意 如果异常处理时 再次 使用 raise 后面什么都没有,那么代表把这个异常还给系统,让解释器用默认的方式处理它. ...
分类:
编程语言 时间:
2018-05-17 00:02:13
阅读次数:
180
1、概览@property 可以让把【方法】当做【属性】调用# 方法源码class Student(object):def get__score(self):return self.__scoredef set__score(self, value):if not isinstance(value, int):raise ValueError(‘score must be an integer!‘
分类:
编程语言 时间:
2018-05-16 11:03:15
阅读次数:
174
1、定义函数
定义一个函数需要有 函数名、参数、函数体。函数体中最好还有 传入的参数判断
?
1.1、函数创建
定义一个函数用def,数据类型检查用isinstance。例子如下:
def
my_abs(x):
??? if not
isinstance(x, (int, float)):??? # 判断传入的参数,是否是 ××× 或 浮点形
??????? raise TypeE
分类:
编程语言 时间:
2018-05-13 10:43:11
阅读次数:
195
题目描述 Farmer John has bought property in the Caribbean and is going to try to raise dairy cows on a big farm composed of islands. Set in his ways, he w ...
分类:
其他好文 时间:
2018-05-12 18:22:42
阅读次数:
225
三个接口: 方法一: >>> help(getattr) Help on built-in function getattr in module __builtin__: getattr(...) getattr(object, name[, default]) -> value Get a nam ...
分类:
其他好文 时间:
2018-05-08 17:42:08
阅读次数:
177
常用模块一 认识模块 什么是模块 模块的导入和使用 常用模块一 collections模块 时间模块 random模块 os模块 sys模块 序列化模块 re模块 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀。 但其实import加载的模块分为四 ...
分类:
其他好文 时间:
2018-05-08 12:19:15
阅读次数:
171
BZOJ_2212_[Poi2011]Tree Rotations_线段树合并 Description Byteasar the gardener is growing a rare tree called Rotatus Informatikus. It has some interesting ...
分类:
其他好文 时间:
2018-05-06 13:40:05
阅读次数:
188