- 使用转换说明符(%s,%f等对字符串进行格式转换)
>>>for1 = "Hello, %s, %s!"
>>>values = ('world','python')
>>>b = for1 %values
- 使用模板
>>>from string import Template
>>>tmp1 = Template("Hello, $who $what enough for ya?")
>>>b = tmp1.substitute(who="Mars", what="dusty")
- format方法
format: 使用字符串来替换原始字符串中由花括号括起的部分,其中可能包含名称,如何对相应的值进行转换及格式设置的信息。
“{}, {} and {}".format('first', 'second', 'third')
"{0} {1} {1} {2}".format("one", "two", "three")