首页后端开发Pythonformat函数公式

format函数公式

时间2023-06-08 09:12:02发布访客分类Python浏览300
导读:format函数公式?python format函数用法详解:1、位置print("hello {0}, this is {1}.".format("world", "python" # 根据位置下标进行填充print("hello {...

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[0]} , this is { names[1]} .".format(names = list))

输出:

hello world, this is python.

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: format函数公式
本文地址: https://pptw.com/jishu/66645.html
webstorm怎样安装代码提示插件 老话题对SA来说用perl还是python比较好

游客 回复需填写必要信息