当前位置:大问百书>生活百科>format函数公式

format函数公式

2024-07-11 01:37:58 编辑:zane 浏览量:674

format函数公式

的有关信息介绍如下:

format函数公式

python format函数用法详解:

1、位置

print("hello {0}, this is {1}.".format("world", "python")) # 根据位置下标进行填充

print("hello {}, this is {}.".format("world", "python")) # 根据顺序自动填充

print("hello {0}, this is {1}. {1} is a new language.".format("world", "python")) # 同一参数可以填充多次

输出:

hello world, this is python.

hello world, this is python.

hello world, this is python. python is a new language.

2、key

obj = "world"

name = "python"

print("hello {obj}, this is {name}.".format(obj = obj, name = name))

输出:

hello world, this is python.

3、列表

list = ["world", "python"]

print("hello {names}, this is {names}.".format(names = list))

输出:

hello world, this is python.

版权声明:文章由 大问百书 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.dawenbaishu.com/life/20769.html
热门文章