Python2.6 最先,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功用。
基础语法是经由过程 {} 和 : 来替代之前的 % 。
format函数能够接收不限个参数,位置能够不按递次。
实例
>>>"{} {}".format("hello", "world") # 不设置指定位置,按默许递次 'hello world' >>> "{0} {1}".format("hello", "world") # 设置指定位置 'hello world' >>> "{1} {0} {1}".format("hello", "world") # 设置指定位置 'world hello world'
相干引荐:《Python教程》
以上就是format在python中是什么意义的细致内容,更多请关注ki4网别的相干文章!