摘要: 1 def crypt(source,key): 2 from itertools import cycle 3 result='' 4 temp=cycle(key) 5 for ch in source: 6 result=result+chr(ord(ch)^ord(next(temp))) 7 return resul... 阅读全文
posted @ 2017-06-08 14:08 JustLittle 阅读(8294) 评论(0) 推荐(0)
摘要: 1 import textwrap 2 doc='''Beautiful is better than ugly. 3 Explicit is better than implicit. 4 Simple is better than complex. 5 complex is better than complicated. 6 Flat is better than dense.... 阅读全文
posted @ 2017-06-08 13:54 JustLittle 阅读(1822) 评论(0) 推荐(0)
摘要: 1 ''' 2 center()、ljust()、rjust(),返回指定宽度的新字符串,原字符串居中、左对齐或右对齐出现在新字符串中, 3 如果指定宽度大于字符串长度,则使用指定的字符(默认为空格进行填充)。 4 ''' 5 print('Hello world!'.center(20)) #居中对齐,以空格进行填充 6 # Hello world! ... 阅读全文
posted @ 2017-06-08 10:54 JustLittle 阅读(5768) 评论(0) 推荐(0)
摘要: 1 ''' 2 eval()用来把任意字符串转化为Python表达式并进行求值 3 ''' 4 print(eval('3+4')) #计算表达式的值 5 a=3 6 b=4 7 print(eval('a+b')) #这时候要求变量a和b已存在 8 import math 9 eval('help(math.sqrt)') 10 # Help on built - in f... 阅读全文
posted @ 2017-06-07 21:28 JustLittle 阅读(1280) 评论(0) 推荐(0)
摘要: 1 ''' 2 strip()、rstrip()、lstrip()分别用来删除两端、右端、左端、连续的空白字符或字符集 3 ''' 4 s='abc ' 5 s2=s.strip() #删除空白字符 6 print(s2) 7 #abc 8 s3='\n\nhello world \n\n'.strip() #删除空白字符 9 print(s3) 10 # hello... 阅读全文
posted @ 2017-06-07 15:10 JustLittle 阅读(57281) 评论(2) 推荐(1)
摘要: 1 ''' 2 maketrans()、translate() 3 maketrans()方法用来生成字符映射表,而translate()方法则按映射表中定义的对应关系转换并替换其中的字符,使用这两个方法的组合可以 4 同时处理多个不同的字符,replace()方法则无法满足这一要求。 5 ''' 6 #创建映射表,将字符'abcdef123'一一地转换为'uvwxyz@#$' 7... 阅读全文
posted @ 2017-06-07 14:47 JustLittle 阅读(3976) 评论(0) 推荐(0)
摘要: 1 ''' 2 lower()、upper()、capitalize()、title()、swapcase() 3 这几个方法分别用来将字符串转换为小写、大写字符串、将字符串首字母变为大写、将每个首字母变为大写以及大小写互换, 4 这几个方法都是生成新字符串,并不对原字符串做任何修改 5 ''' 6 s='What is Your Name?' 7 s2=s.lower() 8 ... 阅读全文
posted @ 2017-06-07 14:45 JustLittle 阅读(46241) 评论(2) 推荐(2)
摘要: 1 #join() 与split()相反,join()方法用来将列表中多个字符串进行连接,并在相邻两个字符串之间插入指定字符 2 li=['apple','peach','banana','pear'] 3 sep=',' 4 s=sep.join(li) 5 print(s) #使用逗号作为连接符 6 s1=':'.join(li) #使用冒号作为连接符 7 print(s... 阅读全文
posted @ 2017-06-06 21:32 JustLittle 阅读(1596) 评论(0) 推荐(0)
摘要: 1 #字符串常用方法 2 s='apple,peach,banana,peach,pear' 3 #返回第一次出现的位置 4 print(s.find('peach')) 5 #指定位置开始查找 6 print(s.find('peach',7)) 7 #指定范围中进行查找 8 print(s.find('peach',7,20)) 9 #从字符串尾部向前查找 10 prin... 阅读全文
posted @ 2017-06-06 20:28 JustLittle 阅读(2331) 评论(0) 推荐(1)
摘要: 1 #冒泡排序 2 array = [1,2,3,6,5,4] 3 for i in range(len(array)): 4 for j in range(i): 5 if array[j] > array[j + 1]: 6 array[j], array[j + 1] = array[j + 1], array[j] 7 pri... 阅读全文
posted @ 2017-06-05 21:42 JustLittle 阅读(1223) 评论(0) 推荐(0)