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

全部都正确输出了。

posted @ 2016-02-04 14:40  黄小墨  阅读(1524)  评论(0编辑  收藏  举报