内置函数
![](https://img-blog.csdnimg.cn/img_convert/78461e613f05ab4ac6a50f7532d30e7f.png)
![](https://img-blog.csdnimg.cn/img_convert/3f2efef01a1b1edeaaff86a6a2cecd71.png)
![](https://img-blog.csdnimg.cn/img_convert/97c23e3cdd68210fdeb8253cfe05e7cc.png)
字符串不可以和数字相加
![](https://img-blog.csdnimg.cn/img_convert/827695d80bd86e2c9efb75f30f2a347c.png)
![](https://img-blog.csdnimg.cn/img_convert/f70b8357cb19e076ebb77450afbb6483.png)
![](https://img-blog.csdnimg.cn/img_convert/e6ff811d759ed8812c54001cc9e9c1bd.png)
![](https://img-blog.csdnimg.cn/img_convert/605f6082db02ea3ed4bcbbbb74adec98.png)
![](https://img-blog.csdnimg.cn/img_convert/6b91021975a8c7787bbdf9f7619031d9.png)
range可以设置遍历的间隔
![](https://img-blog.csdnimg.cn/img_convert/e810df66816e3859dbcaab7130bcb32e.png)
![](https://img-blog.csdnimg.cn/img_convert/3174bce30af7a40ba148dc28e0969fda.png)
![](https://img-blog.csdnimg.cn/img_convert/cd6ed9f00c170b7873d0eb2509aea39d.png)
匿名函数
b是一个匿名函数,b(1)表示将1传给了参数x,函数体执行了x+1,所以结果为2
![](https://img-blog.csdnimg.cn/img_convert/780ee9cc950b190617fce1eddf336bc3.png)
定义一个函数
无参函数
![](https://img-blog.csdnimg.cn/img_convert/414fbaf39353321e962836f0e85fbbee.png)
带参函数
![](https://img-blog.csdnimg.cn/img_convert/ee8c284ddf711b37f1411ff8e32da152.png)
![](https://img-blog.csdnimg.cn/img_convert/0197df3929e29317a79029e03c727cc5.png)
函数返回值,函数中可以用return给函数返回值,遇到return后,函数将不再执行
![](https://img-blog.csdnimg.cn/img_convert/f8b1f6b0fc053bc4412ea42b1d648730.png)
![](https://img-blog.csdnimg.cn/img_convert/d8449087347d4a9dfca690c64da5cd75.png)
参数默认值,参数age默认是12
![](https://img-blog.csdnimg.cn/img_convert/3a4a0e2c4e37839cbdacbfa5dcdbf100.png)
修改参数默认值,调用的时候age修改为18
![](https://img-blog.csdnimg.cn/img_convert/ba1b3b2fa5752deeca774f1613d93802.png)
![](https://img-blog.csdnimg.cn/img_convert/8435dcf080a29e6282cd5a9b2feeca27.png)
可变参数 *args 代表一个元组,**kwargs代表一个字典
![](https://img-blog.csdnimg.cn/img_convert/0177b1a0af9652a2ebf6543a73af0e1e.png)
![](https://img-blog.csdnimg.cn/img_convert/ed270f216e94388b75a5dc87d8e2728f.png)
装饰器
1.装饰器本身是一个函数
2.参数势函数
3.返回值是函数
![](https://img-blog.csdnimg.cn/img_convert/17eda2df49c552072f7febed255890ad.png)
执行流程:
第一步: 调用装饰器 warp,执行return inner
第二步: 执行innner函数,return res
第三步: 执行res函数,调用被装饰函数
调用装饰器
![](https://img-blog.csdnimg.cn/img_convert/633192220a21f5c729072128d7e9f4be.png)
![](https://img-blog.csdnimg.cn/img_convert/8c2f4cfee80774485f42030c60f213ab.png)
打印被装饰参数
![](https://img-blog.csdnimg.cn/img_convert/5bdb258b73bd8ae097c4e50cfec96ddd.png)
![](https://img-blog.csdnimg.cn/img_convert/a6fbbf5f183fbc21fff5054fa05b84b6.png)
装饰器案例(计算函数执行时间)
![](https://img-blog.csdnimg.cn/img_convert/b2fc6c5055347e3da3ddb6406f1a73f0.png)