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'))
相关文章
相关标签/搜索