40、經常使用字符串格式化有哪幾種?

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'))
相關文章
相關標籤/搜索