摘要: #rjust(12,'l')"12是字符串的长度,l是当字符串不够长的时候,用l填充。并且字符串右对齐"。返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串。如果指定的长度小于字符串的长度则返回原字符串l=["123","1252454","894651245"]for i in 阅读全文
posted @ 2017-09-07 23:04 糖宝虫 阅读(354) 评论(0) 推荐(0) 编辑
摘要: a=[1,2,3,4]print(repr(a))print(type(repr(a)))for i in repr(a): print(i)#repr函数是将对象转换成string类型 阅读全文
posted @ 2017-09-07 20:16 糖宝虫 阅读(317) 评论(0) 推荐(0) 编辑
摘要: import randoma=[]for i in range(9): b=random.randint(0,9)#生产9个随机数 a.append(b)#把生成的随机数添加到列表里面print(sorted(a))#对列表进行排序 阅读全文
posted @ 2017-09-07 17:02 糖宝虫 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 需要逆向循环序列的话,先正向定位序列,然后调用 reversed() 函数。 for i in reversed(range(1, 10, 2)): print(i)97531 阅读全文
posted @ 2017-09-07 15:21 糖宝虫 阅读(187) 评论(0) 推荐(0) 编辑
摘要: a=[1,2,3]b=[4,5,6]for A ,B in zip(a,b):#用zip()函数整体打包 print(A,B) 阅读全文
posted @ 2017-09-07 15:19 糖宝虫 阅读(104) 评论(0) 推荐(0) 编辑
摘要: d={"A":"a","B":"b","C":"c","D":"d"}c=d.items()#字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。for a,b in c: print(a,b)b=enumerate(c)#对于一个可迭代的(iterable) 阅读全文
posted @ 2017-09-07 14:55 糖宝虫 阅读(171) 评论(0) 推荐(0) 编辑