摘要: 1. 匹配字符串中的一个百分比数字 import re t = 'yuchen is a very lovely girl. 5.568% company ltd.' match = re.search(r"\d+\.\d*%", t) print(match.group()) 2.匹配小括号()里 阅读全文
posted @ 2018-12-01 13:48 coffee~ 阅读(756) 评论(0) 推荐(0) 编辑
摘要: from decimal import Decimal # .2f设置小数位精确位数, 如下返回2.55 q = 2.551 t = format(Decimal(q), '.2f') #向上取2位小数, 返回2.56 q = 2.551 t = format(Decimal( q + 0.005) 阅读全文
posted @ 2018-12-01 12:55 coffee~ 阅读(916) 评论(0) 推荐(0) 编辑