随笔分类 -  python

摘要:def outter(func): def wrapper(*args,**kwargs): res = func(*args,**kwargs) return res return wrapper@outterdef index(x,y): print(x,y)"""偷梁换柱后index的参数是什 阅读全文
posted @ 2020-12-15 21:09 正霜霜儿 阅读(144) 评论(0) 推荐(0) 编辑
摘要:#装饰器"""1. 什么是装饰器 器指的是工具,可以定义成函数 装饰指的是为其他事物添加额外的东西来点缀 合到一起的解释: 装饰器指的是定义一个函数,该函数是用来装饰其他函数的,为其他函数添加额外的功能的2.为何要用装饰器 开放封闭原则 开放:指的是拓展功能是开放 封闭:指的是对源代码是封闭的, 不 阅读全文
posted @ 2020-12-14 21:55 正霜霜儿 阅读(87) 评论(0) 推荐(0) 编辑
摘要:#ATM 练习 def login(): print("登陆功能") def transfer(): print("转账功能") def check_balance(): print("查询余额") def register(): print("注册功能") while True: print("" 阅读全文
posted @ 2020-12-13 21:49 正霜霜儿 阅读(92) 评论(0) 推荐(0) 编辑
摘要:#1.可以把函数当作变量去用,可以赋值# func=内存地址 def func(): print("from func") f=func print(f,func) f() func() <function func at 0x105f071f0> <function func at 0x105f0 阅读全文
posted @ 2020-12-13 21:45 正霜霜儿 阅读(75) 评论(0) 推荐(0) 编辑
摘要:nonlocal 学习:修改函数外层函数包含名字对应的值(不可变类型)示范1: x=11 def f1(): x=22 def f2(): x=33 print(x) #输出f2的值 f2() print(x)#输出的是f1的值 f1() print(x)#输出的就是全局的值 33 22 11 示范 阅读全文
posted @ 2020-12-13 10:42 正霜霜儿 阅读(277) 评论(0) 推荐(0) 编辑
摘要:#一,形式参数和实参"""在定义函数阶段定义的参数称之为形参,相当于变量名"""# def fun(x,y): #x=1,y=2# print(x,y)"""实参,在调用函数的阶段,传入的值称之为实际参数,简称实参,相当于变量值"""# fun(1,2)#关系:#在调用阶段,实参(变量值)会赋值给形 阅读全文
posted @ 2020-12-10 22:57 正霜霜儿 阅读(125) 评论(0) 推荐(0) 编辑
摘要:函数 #def 函数名(参数1,参数2): # """文档描述""" # 函数体 # return n"""定义函数的三种方式"""#形式一,无参数# def func():# print("hahaha")# func()#定义函数发生的事情# 1,申请内存空间保存函数代码# 2,将上述内存地址绑 阅读全文
posted @ 2020-12-09 23:35 正霜霜儿 阅读(242) 评论(0) 推荐(0) 编辑
摘要:#f= open(r"aaa/a.txt",mode='rt') # f的值是一种变量,占用的是应用程序的内存空间,此时牵扯的是两个方面的资源#print(f)##2.操作文件:读/写文件,应用程序对文件的读写请求都是向操作系统调用,然后由操作系统控制把硬盘把输入读入内存,或者写入硬盘#res=f. 阅读全文
posted @ 2020-12-08 20:56 正霜霜儿 阅读(252) 评论(0) 推荐(0) 编辑
摘要:break代表结束本层循环,而continue则用于结束本次循环,直接进入下一次循环 continue##打印1-10 除了7的数字number=11 while number>1: number -= 1 if number==7: continue # 结束掉本次循环,即本次循环continue 阅读全文
posted @ 2020-12-07 16:24 正霜霜儿 阅读(398) 评论(0) 推荐(0) 编辑
摘要:# 浅拷贝(copy):拷贝父对象,不会拷贝对象的内部的子对象。# 深拷贝(deepcopy): copy 模块的 deepcopy 方法,完全拷贝了父对象及其子对象#list2=list1 -->这个不叫拷贝 list1 =[1,2,[11,22,33],{"a":1,"b":2}] list2= 阅读全文
posted @ 2020-12-06 21:40 正霜霜儿 阅读(113) 评论(0) 推荐(0) 编辑
摘要:遇到这个问题的时候发现网上给的解释是:https://stackoverflow.com/questions/1250103/attributeerror-module-object-has-no-attribute 有个外国人遇到的情况如下: Not sure how but the below 阅读全文
posted @ 2020-12-06 21:38 正霜霜儿 阅读(1646) 评论(0) 推荐(0) 编辑
摘要:来源:https://mp.weixin.qq.com/s?__biz=MzAwOTQ4MzY1Nw==&mid=2247495678&idx=1&sn=973910f021a4d54fb800cd7fa2286a92&chksm=9b5c4b18ac2bc20e033c7ed70684facb75 阅读全文
posted @ 2020-11-25 09:13 正霜霜儿 阅读(297) 评论(0) 推荐(0) 编辑
摘要:echo alias python=python3 >> ~/.bashrc source ~/.bashrc 反之,如果仍然需要Python2.7 ,则改成2.7就行。 update :2020/5/10: 就是在~/.bashrc中添加别名映射 比如,我想快捷方式关机,则可以在~/.bashrc 阅读全文
posted @ 2019-10-23 14:30 正霜霜儿 阅读(835) 评论(0) 推荐(0) 编辑
摘要:知识来源:https://zhuanlan.zhihu.com/p/73975013 1.环境 os:MAC tool:python 3.7 ,pip3.7 2.前提: 使用pip3.7 install pillow and wxpy 模块 3.开始: 1 from wxpy import * 2 阅读全文
posted @ 2019-08-19 22:15 正霜霜儿 阅读(731) 评论(0) 推荐(0) 编辑
摘要:常用模块: calendar、time、datetime、timeit、os、shutil、zip、math、string 上述所有的模块使用理论上都应该先导入,string是特例 -calendar,time,datatime的区别参考中文意思 calendar: -跟日历相关的模块 获取一年的日 阅读全文
posted @ 2019-06-24 22:17 正霜霜儿 阅读(227) 评论(0) 推荐(0) 编辑
摘要:递归:函数间接或者直接调用自己 递归分两个过程 1、往下调用,分解的过程 2、往上回溯,综合的过程 递归的条件: 一定要有结束的条件 例子:阶乘: 斐波那契数列: 阅读全文
posted @ 2019-06-23 17:11 正霜霜儿 阅读(169) 评论(0) 推荐(0) 编辑
摘要:在学习汉娜塔的时候,遇到一个error RecursionError: maximum recursion depth exceeded in comparison 经过百度,百度的方法: 加上: import sys sys.setrecursionlimit(100000) 可是我加上之后结果如 阅读全文
posted @ 2019-06-23 16:43 正霜霜儿 阅读(6511) 评论(0) 推荐(0) 编辑
摘要:https://yiyibooks.cn/xx/python_352/library/re.html 看command: 阅读全文
posted @ 2019-06-19 11:07 正霜霜儿 阅读(6919) 评论(0) 推荐(0) 编辑
摘要:在运行python中因为添加了中文注释,遇到SyntaxError: Non-UTF-8 code starting with '\xb8' in file 经过百度,说是Python的默认编码格式是UTF-8,若指定编码格式则需在开头添加如下代码: 阅读全文
posted @ 2019-06-19 10:41 正霜霜儿 阅读(10724) 评论(0) 推荐(0) 编辑
摘要:定义在函数内部的变量拥有一个局部作用域,定义在函数外的拥有全局作用域。 局部变量只能在其被声明的函数内部访问,而全局变量可以在整个程序内访问。 在调用函数的时候,所有在函数内声明的变量名称都被加到作用域中:👇👇👇 但是,当内部作用域想要修改外部作用域的变量的时候,就可以用到global和non 阅读全文
posted @ 2019-06-04 22:37 正霜霜儿 阅读(3581) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示