Python格式化输出
print(‘name: %s,version: %s,code: %d‘ %(‘Python‘,3.6,3)) print(‘name: {name},version: {version},code: {code}‘ %{‘name‘:‘Python‘,‘version‘:3.6 ,‘code‘:3})
Python字符串格式化
#{} 不能重复 有序 res = ‘name: {},version: {},code: {}‘.format(‘Python‘,‘3.6‘,3) #{0} 可以重复 有序 res1 = ‘name: {0},version: {1},code: {1}.{0} is an easy to learn‘.format(‘Python‘,‘3.6‘,3) #{name} 键值对 无序 res2 = ‘name: {name}, version: {version}, code: {name} {code}.is an easy to learn‘.format(name = ‘Python‘,version = ‘3.6‘,code = 3) print(res) print(res1) print(res2)