摘要: 有的时候,我们需要将函数作为返回值,以下为代码: def superfunc(): i = 0 def wrapper(): nonlocal i i +=1 return i return wrapper A = superfunc() print(A(), A(), A()) 输出:1 2 3 阅读全文
posted @ 2020-03-27 22:59 Johnthegreat 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 在给列表排序时,sorted非常好用,语法如下: sorted(iterable[, cmp[,key[,reverse]]]) 简单列表排序,很容易完成,sorted(list)返回的对象就是列表结果,但是遇到列表中嵌套元组时,需要使用特殊的方法解决。 问题描述: 给定列表如下: list_exa 阅读全文
posted @ 2020-03-27 22:19 Johnthegreat 阅读(292) 评论(0) 推荐(0) 编辑