python(3)-动态参数实现字符串格式化
s1 = "{0} ===> {1}" s = s1.format('lilei', 'boy') print(s) l = ['lilei', 'boy'] s = s1.format(*l) print(s) s1 = "{name} ===> {acter}" s = s1.format(name='lilei', acter='boy') print(s) d = {'name':'lilei', "acter":'boy'} s = s1.format(**d) print(s)
看看执行结果
lilei ===> boy lilei ===> boy lilei ===> boy lilei ===> boy
全部都正确输出了。