2017年12月21日

python set集合运算(交集,并集,差集,对称差集)

摘要: 1》交集>>> x={1,2,3,4}>>> y={3,4,5,6}>>> xset([1, 2, 3, 4])>>> yset([3, 4, 5, 6])>>> x&yset([3, 4])>>> x.intersection(y)set([3, 4])2》并集>>> x | y #集合并集set 阅读全文

posted @ 2017-12-21 14:26 林肯公园 阅读(65293) 评论(0) 推荐(2)

python字符串操作

摘要: 去空格及特殊符号 s.strip().lstrip().rstrip(',') 复制字符串 #strcpy(sStr1,sStr2) sStr1 = 'strcpy' sStr2 = sStr1 sStr1 = 'strcpy2' print sStr2 连接字符串 #strcat(sStr1,sStr2) sStr1 = 'strcat' sStr2 = 'append' sStr1 ... 阅读全文

posted @ 2017-12-21 14:08 林肯公园 阅读(273) 评论(0) 推荐(0)

Python日期的加减等操作

摘要: 所有日期、时间的api都在datetime模块内。 1. datetime => string now = datetime.datetime.now() now.strftime('%Y-%m-%d %H:%M:%S') #输出2012-03-05 16:26:23.870105 strftime 阅读全文

posted @ 2017-12-21 11:36 林肯公园 阅读(87571) 评论(0) 推荐(1)

python zfill方法给字符串前面补0

摘要: 正数补前面补0 n = "123" s = n.zfill(5) assert s == "00123" zfill()也可以给负数补0 n = "-123" s = n.zfill(5) assert s == "-0123" 对于纯数字,我们也可以通过格式化的方式来补0 n = 123 s = "%05d" % n assert s == "00123" 阅读全文

posted @ 2017-12-21 11:23 林肯公园 阅读(1189) 评论(0) 推荐(0)

导航