format使用

1.字典

a={
    'bakend': 'www.oldboy.org',
    'balance':'roudrobin',
    'record':{
        'server': '100.1.7.9',
        'weight': 20,
        'maxconn': 30
            }
        }

print(a)

cfg1='''
backend {bakend}
        balance {balance}
        server {record[server]} weight {record[weight]} maxconn {record[maxconn]}
'''.format(**a)


2.str

 '姓名:%s, 年龄:%d' % ('walker', 99)
'姓名:walker, 年龄:99'

 

>>> '姓名:{name}, 年龄:{age}, 工龄:{age}'.format(name='walker', age=99)
'姓名:walker, 年龄:99, 工龄:99'

 

3.tuple 元组

 

posted @ 2017-06-29 11:11  陈奕迅-可以了  阅读(135)  评论(0编辑  收藏  举报