python三种格式化输出

name = '张三'
age = 22
job = Engineer
salary = 99999999

info1 = '''
---------- info1 of %s ----------
name:%s
age:%d
job:%s
salary:%s ''' %(name,name,int(age),job,salary)
print(info1)

info2 = '''
--------- info2 of {name}---------
name:{name}
age:{age}
job:{job}
salary:{salary} '''.format(name=name,age=age,job=job,salary=salary)
print(info2)

info3 = '''
--------- info of {0}---------
name:{0}
age:{1}
job:{2}
salary:{3} '''.format(name,age,job,salary)
print(info3)
posted @ 2017-03-28 08:52  ccskun  阅读(364)  评论(0编辑  收藏  举报