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'))