from itertools import islice
gen =iter(range(10))for i in islice(gen,2,6):print(i)
13.json与字典的相互转换
import json
json_str = json.dumps(d)
d = json.loads(json_str)
14.字符串格式化的方式
%格式化
模板字符串
format方法
fstring
15.正则匹配,将匹配值格式化,然后替换
import re
deffun(matched):returnformat(float(matched.group()),'0.2f')
result = re.subn('-?\d+(\.\d+)?', fun,'PI is 3.1415926, e is 2.71828183, -0.2 + 1.3 = 1.1')print(result)