python 字符串格式化

1,基本用法

  1,正常拼串

    s1 = '%s aaa %s'('alice','bob')

  2.format

   不带编号

   s1 = '{} aaa {}'

   s1.format('hello','world')

   带编号

   s1 = '{1} aaaa {2} bbb {1}'

   s.format('hello','world')

   hello aaaa world hello

  命名

  s1 = '{a} aaa {b} bbbb {a}'

  s.format(a='hello',b='world')

 

posted on 2018-06-23 11:13  么么唧唧  阅读(163)  评论(0编辑  收藏  举报

导航