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


Python的字符串格式化常用的有三種!

  第一種最方便的

  缺點:需一個個的格式化

print('hello %s and %s'%('df','another df'))

 

  第二種最好用的

  優點:不需要一個個的格式化,可以利用字典的方式,縮短時間

print('hello %(first)s and %(second)s'%{'first':'df' , 'second':'another df'})

  第三種最先進的

    優點:可讀性強

print('hello {first} and {second}'.format(first='df',second='another df'))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM