1.首先,format函数是基于3.9的Python解释器。
一,format函数的参数:
format函数可以有一个或者多个参数。
str="{} {}".format("hello", "world") # 按照一一对应的顺序输出
print(str)
str="{0} {1}".format("hello", "world") # 按照元素下标输出
print(str)
str="{1} {0} {1}".format("hello", "world") # 按照元素下标输出
print(str)
str="{name} {age} {grade}".format(name='mike',age=18,grade='A+')
print(str)
str="{age} {name} {grade}".format(name='mike',age=18,grade='A+')
print(str)
str="{name} {grade}".format(name='mike',age=18,grade='A+')
print(str)
输出:
hello world
hello world
world hello world
mike 18 A+
18 mike A+
mike A+
因此,我们可以得出结论,那个所有的常见字符可以作为format函数里面的下标。
文献参考:
Python format 格式化函数 | 菜鸟教程 (runoob.com)
python--print函数的格式化输出_liuyingying0418的博客-CSDN博客_python中print的输出格式