![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
Andrew9tech
这个作者很懒,什么都没留下…
展开
-
常见函数
cmp(x, y)中文说明:比较两个对象x和y,如果x y,返回正数。版本:该函数只有在python2中可用,而且在python2所有版本中都可用。但是在python3中该函数已经被删减掉,这点要特别注意。原创 2014-07-28 23:27:41 · 378 阅读 · 0 评论 -
strip()、 lstrip()、 rstrip()使用方法
Python中的strip用于去除字符串的首位字符,同理,lstrip用于去除左边的字符,rstrip用于去除右边的字符。这三个函数都可传入一个参数,指定要去除的首尾字符。注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符,直到没有匹配的字符,比如: 复制代码代码如下:theString = 'saaaay yes no y原创 2014-07-29 21:07:23 · 501 阅读 · 0 评论 -
raw_input 读取输入值
下面介绍了python raw_input的用法,使用raw_input 能够很方便的丛控制台读入数据。1.输入字符串#13222319810101****nID = ''while 1: nID = raw_input("Input your id plz") if len(nID) != len("13222319810101****"):转载 2014-07-28 22:01:13 · 588 阅读 · 0 评论 -
while-else举例
def showMaxFactor(num): count = num / 2 while count > 1: if num % count == 0: print 'largest factor of %d is %d' % (num, count) break count -= 1原创 2014-07-29 23:14:11 · 440 阅读 · 0 评论 -
zip()函数用法举例
定义:zip([iterable, ...])zip()是Python的一个内建函数,它接受一系列可迭代的对象作为参数,将对象中对应的元素打包成一个个tuple(元组),然后返回由这些tuples组成的list(列表)。若传入参数的长度不等,则返回list的长度和参数中长度最短的对象相同。利用*号操作符,可以将list unzip(解压),看下面的例子就明白了:>>> a = [1,2原创 2014-07-29 22:52:25 · 558 阅读 · 0 评论 -
Python heapq模块
heapq模块提供了如下几个函数:heapq.heappush(heap, item) 把item添加到heap中(heap是一个列表)heapq.heappop(heap) 把堆顶元素弹出,返回的就是堆顶heapq.heappushpop(heap, item) 先把item加入到堆中,然后再pop,比heappush()再heappop()要快得多h原创 2015-05-18 16:30:22 · 379 阅读 · 0 评论 -
python decode()、encode() 、编码与反编码
python中提到unicode,一般指的是unicode对象,比如:“叫我”的对象为'\u53eb\u6211''.字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码。decode的作用是将其他编码的字符串转换成uni原创 2015-05-24 18:03:57 · 835 阅读 · 0 评论 -
python 全排列
itertools模块现成的全排列:for i in itertools.permutations('abcd',4): print ''.join(i)相关全排列算法:def perm(l): if(len(l)<=1): return [l] r=[] for i in range(len(l)):原创 2015-08-09 11:12:55 · 777 阅读 · 0 评论