摘要: #简单的实例def add(x,y,f): return f(x)+f(y)var = add(5,-9,abs)print(var)1.把一个函数名当做实参传给另外一个函数(在不修改被装饰函数源代码的情况下为其添加功能)2.返回值中包含函数名(不能修改函数的调用方式) import time #对 阅读全文
posted @ 2020-05-12 23:09 安好_世界 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 1.必须要有一个明确的结束条件。 2.每次进入深一层递归时,问题规模相比上次应有所减少。 3.递归效率不高,递归层次过多会导致栈溢出(在计算机中,函数调用是通过栈(stack)这种数据结构实现的,每当进入一个函数调用,栈就会多加一层栈帧,每当函数返回,栈就会减一层栈帧。由于栈的大小不是无限的,所以, 阅读全文
posted @ 2020-05-12 22:27 安好_世界 阅读(128) 评论(0) 推荐(0) 编辑
摘要: school = 'bei feng'#全局变量def change(name): global school #声明更改全局变量 school = 'Linux mage' print('before change',name,school) name = 'liuhao'#局部变量,只在函数里面 阅读全文
posted @ 2020-05-12 22:00 安好_世界 阅读(419) 评论(0) 推荐(0) 编辑
摘要: 1.面向对象 》类 》class 2.面向过程 》过程 》def 3.函数式编程 》函数 》def def fun(x,y): print(x) print(y)fun(1,3)#位置函数fun(y=8,x=9)#关键函数 # def test(*agrgs):#接受位置参数,转换成元组方式# pr 阅读全文
posted @ 2020-05-11 22:59 安好_世界 阅读(173) 评论(0) 推荐(0) 编辑
摘要: GBK转换UTF-8: 方法两种: 1.使用unicode转换。(py3内存中所有字符串都是unicode,unicode是万国码)。注释:py2不行,py2内存中ascii码。 GBK ->解码decode('GBK') ->编码encode('utf-8') 2.转换成UTF-8 阅读全文
posted @ 2020-05-06 22:50 安好_世界 阅读(186) 评论(0) 推荐(0) 编辑
摘要: import sys,time'''#文件句柄f = open("yesterday2",'a',encoding="utf-8")#'r'=read,'w'=write,w是创建文件.a=append追加的意思.默认读模式# print(f.read())#文件光标读取一遍f.write("我爱北 阅读全文
posted @ 2020-05-06 20:59 安好_世界 阅读(133) 评论(0) 推荐(0) 编辑
摘要: list1=[1,5,6,1,8,1,6,7,9,1,6]list1 = set(list1)list2 = set([1,6,88,44,66,33,9])list3=set([1,6])list4=set([11,61])# print(list1,type(list1))print(list1 阅读全文
posted @ 2020-05-04 19:50 安好_世界 阅读(165) 评论(0) 推荐(0) 编辑
摘要: china ={ "江苏": {"南京": {"玄武区": {"中山东路": {"1路","3路","5路","9路","25路","34路","801路","805路","824路"}, "天路":{}, "后路":{} },"秦淮区":{},"鼓楼区":{ 阅读全文
posted @ 2020-04-25 22:58 安好_世界 阅读(276) 评论(0) 推荐(0) 编辑
摘要: info ={ "name":"tengxun", "name1":"ali", "name2":"baidu"}b= { 'name':'liufeng', 1:3, 2:5}# info.update(b)#两个字典和成一个字典# print(info)# print(info.items()) 阅读全文
posted @ 2020-04-25 21:18 安好_世界 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 列表常用方法: name = ['zhangsan','lisi','wangwu','xieqi'] name2=[1,2,3,4] name3 = ['zhangsan','lisi',['cinndy','alise'],'wangwu','xieqi'] print(name[2]) wan 阅读全文
posted @ 2020-04-25 18:18 安好_世界 阅读(237) 评论(0) 推荐(0) 编辑