本文共 1670 字,大约阅读时间需要 5 分钟。
tp1 = "i am {}, age {}, {}".format("seven",18,'alex')print(tp1)
[[fill]align]sign0,[type]
,内容右对齐(默认)
+,正号加正,负号加负;
tpl = "i am {}, age {}, {}".format("seven",18,'alex')tpl = "i am {}, age {}, {}".format(*["seven",18,'alex'])tpl = "i am {0}, age {1}, really {0}".format("seven",18)tpl = "i am {0}, age {1}, really {0}".format(*["seven",18])tpl = "i am {name}, age {age}, really name}".format(name="seven",age=18)tpl = "i am {0[0]}, age {:d}, money {:f}".format("seven",18,88888.1)tpl = "i am {:s}, age {:d}".format(*["seven",age=18])tpl = "i am {name:s}, age {age:d}".format(**{"name": "seven", "age": 18})tpl = "numbers: {:b},{:o},{:d},{:x},{:x}, {:%}".format(15,15,15,15,15.87623,2)tpl = "numbers: {:b},{:o},{:d},{:x},{:x}, {:%}".format(15,15,15,15,15,15,87623,2)tpl = "numbers: {0:b},{0:o},{0:d},{0:x},{0:x},{0:%}".format(15)tpl = "numbers: {num:b},{num:o},{num:d},{num:x},{num:X},{num:%}".format(15)tpl = "numbers: {num:b},{num:o},{num:d},{num:x},{num:X},{num:%}".format(15)
更多格式化操作:
转载地址:http://eyonl.baihongyu.com/