python
来源:互联网 发布:淘宝里的转化率是什么 编辑:程序博客网 时间:2024/06/07 08:12
py部分命令
字符串函数
strip(); //不加参数默认去掉\n
strip(‘o’) //去掉字符串两边的o
split(“x”); //以x为分割符划分
装饰器模式
def outer(func): def inner(): print("hello") print("hello") print("hello") r=func() #func()=原来的f1 print("end") print("end") #print("hello"); #print("hello"); return r #主要目的是拿到原来函数的返回值 return inner@outerdef f1(): print("F1")def f2(): print("F2")def f3(): print("F3")def f100(): print("F100")f1()
在py中@符号有特殊符号;
1.见到@就会执行后面的函数,如@outer即执行outer函数,并且将其下面的函数名当做参数(即把f1当做参数)
2.将outer的返回值重新赋值给f1,即f1=outer的返回值,那么在执行f1的时候,实际上函数体已经发生了变化
将原函数封装到一个函数里面,通过装饰器作用,原来函数名字指向了新的函数体;
主要目的是包含原来函数,因此在装饰器中,通常是包含原来的函数;在原来函数之前和之后加上操作
阅读全文
0 0
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- PHP学习笔记——删除数组中的值实例(猴子选大王)
- maven启动web工程
- surfaceiew 和texture view
- poj 2191 大数素数判定 && 大数素数分解
- tomcat日志配置-----自带log(一)
- python
- xcode soundtouch 一次编译armv7 armv7s arm64 i386 i64 库
- LeetCode 39 Combination Sum
- nth-child选择器用于表格
- 四元素与欧拉角之间的转换
- Find them, Catch them POJ
- ssm中mybatis处理数据库(mysql)与pojo属性中类型不一致(string转date)
- Open JDK源码下载地址
- 每周荐书:SQL优化、深度学习、数据科学家(评论送书)