Python的字符串格式化經常使用的有三種!spa
第一種:最方便的code
缺點:需一個個的格式化orm
print('hello %s and %s'%('df','another df'))
第二種:最好用的blog
優勢:不須要一個個的格式化,能夠利用字典的方式,縮短期字符串
print('hello %(first)s and %(second)s'%{'first':'df' , 'second':'another df'})
第三種:最早進的form
優勢:可讀性強class
print('hello {first} and {second}'.format(first='df',second='another df'))