python format函数

https://www.runoob.com/python/att-string-format.html

 

print('{} {}'.format("name","gender"))

print("网站名:{name}, 地址 {url}".format(name="菜鸟教程", url="www.runoob.com"))

# 通过字典设置参数

site = {"name": "菜鸟教程", "url": "www.runoob.com"}

print("网站名:{name}, 地址 {url}".format(**site))

 

 

# 通过列表索引设置参数

my_list = ['菜鸟教程', 'www.runoob.com']

print("网站名:{0[0]}, 地址 {0[1]}".format(my_list)) # "0" 是必须的

posted @ 2022-03-09 11:02  Tomorrow1126  阅读(24)  评论(0编辑  收藏  举报