Python Node
Evan10242
这个作者很懒,什么都没留下…
展开
-
Python assert 用法
Python中assert用来判断语句的真假,如果为假的话将触发AssertionError错误python help document的解释:Assert statements are a convenient way to insert debugging assertions into a program:例:>>> a = 3>>> assert a ==3>>>原创 2017-04-20 21:54:55 · 445 阅读 · 0 评论 -
记录redis MD5数据库入库去重
记录下mysql 入库去重:import hashlib, redisred = redis.Redis(host="118.26.185.188", port=6379)mdkey = hashlib.md5()mdkey.update(a+b+c+d+g+i)zhujian = mdkey.hexdigest()if not self.red.get(zhujian):原创 2017-08-10 15:43:49 · 890 阅读 · 0 评论 -
python 3 requests模块
点击打开链接大牛整理的转载 2017-06-21 17:32:52 · 312 阅读 · 0 评论 -
Python case str[::-1]
Instructions:Reverse every other word in a given string, then return it. Don't forget to include the spaces!def test(s): rr = [] a = s.split(' ') for i in a : # if i 角标为偶数原创 2017-04-27 10:14:38 · 852 阅读 · 0 评论 -
Python isinstance
记录isinstance 例子一个:给出列表,输出整数部分列表例子:def filter_list(l): a = l c = [] for x in a: if isinstance(x,int)==True: c.append(x) return cisinstance 用来判断数据类型原创 2017-04-26 12:48:24 · 274 阅读 · 0 评论 -
Python count()
Python count() 方法用于统计字符串里某个字符出现的次数。可选参数为在字符串搜索的开始与结束位置。count()方法语法:str.count(sub, start= 0,end=len(string))sub -- 搜索的子字符串start -- 字符串开始搜索的位置。默认为第一个字符,第一个字符索引值为0。end -- 字符串中结束搜索的位置。字符中第一个字符的索原创 2017-05-08 11:30:29 · 484 阅读 · 0 评论 -
Python isdigit()
isdigit() 是判断字符串是否只为数字组成,返回True or Falsestr.isdigit()原创 2017-05-05 14:21:08 · 528 阅读 · 0 评论 -
Python replace()
replace 是将字符串old替换为newstr.replace(old, new[, max])>>> a = 'sdfaf,sda,f,dsaf,asd,f,sadf,'>>> a.replace(',','')'sdfafsdafdsafasdfsadf'max为替换不超过max次数>>> a.replace('sd','77',2)'77faf,77a原创 2017-05-05 13:55:07 · 679 阅读 · 0 评论 -
Python 错误处理
当我们认为某些代码可能会出错时,就可以用try来运行这段代码,如果执行出错,则后续代码不会继续执行,而是直接跳转至错误处理代码,即except语句块,执行完except后,如果有finally语句块,则执行finally语句块,至此,执行完毕。例:>>> a = bTraceback (most recent call last): File "", line 1, in原创 2017-04-22 14:11:23 · 436 阅读 · 0 评论 -
Python 菲波那切数列
菲波那契数列指的是这样一个数列:1,1,2,3,5,8,13,21 ,34,55 , 89 , 144 ……这个数列从第三项开始,每一项都等于前两项之和例:def feb(max): n,a,b = 0,0,1 L = [] while n L.append(b) a,b = b,a+b原创 2017-04-22 13:52:34 · 1774 阅读 · 0 评论 -
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
pip install 包报错:TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'解决:·TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'·sudo apt-get install python-pip原创 2018-02-01 12:02:23 · 5941 阅读 · 0 评论