python 语言
早起的鸟儿有虫吃h
这个作者很懒,什么都没留下…
展开
-
Python函数 extend()和append()的区别
extend()和append()功能类似,但在处理多个列表时,返回的结果完全不同。>>> a=[1,2,3]>>> b=[4,5,6]>>> a.append(b)>>> a[1, 2, 3, [4, 5, 6]]>>> a=[1,2,3]>>> a.extend(b)>>> a[1, 2, 3, 4, 5, 6]转载 2017-08-10 18:26:27 · 430 阅读 · 0 评论 -
python函数 传递多个参数
对于函数要处理不定长的参数,形参任意多个,实参一个 *dict_args ,加*号例如:param = { 'key': '22d6f93f929728c10ed86258653ae14a', 'keywords': u'小区', 'city': '021', 'citylimit': 'true', 'output': 'json',原创 2017-08-10 18:32:55 · 5699 阅读 · 0 评论 -
python 3.x 错误 ‘generator’ object has no attribute ‘next’
用Python生成斐波那契數列def fab(max): n,a,b=0,0,1 while n<max: yield b a,b=b,a+b n=n+1for n in fab(5): print(n)运行正常当运行下面的方式时f=fab(5)f.next()出现下面的错误Traceback (most recent cal转载 2017-09-01 09:27:26 · 718 阅读 · 0 评论 -
python json.dumps() 与 json.dump()
原:http://www.cnblogs.com/wswang/p/5411826.html首先说明基本功能:dumps是将dict转化成str格式,loads是将str转化成dict格式。dump和load也是类似的功能,只是与文件操作结合起来了。 看代码实例:12345678转载 2017-09-01 17:37:03 · 1224 阅读 · 0 评论 -
callback回调函数 python
作者:桥头堡链接:http://www.zhihu.com/question/19801131/answer/27459821来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。转载 2017-09-02 00:08:05 · 338 阅读 · 0 评论 -
python3 sorted( ) 没有 cmp参数, 使用 cmp的方法
一般的 sorted 排序函数 都有相应的 cmp函数,用来定制化排序的比较方法。然而 python 3中的 sorted( ) 除去的cmp 参数,推荐使用 key。Python中有相应的函数 支持将 cmp函数转化为key的值。import functoolsdef tcmp(a,b): if a &gt; b : return -1 elif a &lt; b : ret...原创 2018-09-19 17:15:46 · 11260 阅读 · 6 评论