Python format语法

a = {"name" : "alex","age":16}

v = "my name is {name}, my age is {age}".format(**a)    **字典可以将字典拆分为(name = "alex",age = 16)

如果a是列表的话

a = ["name",16]

v = "my name is {},my age is {}".format(*a)     *可以将列表遍历为("name","16")

posted @ 2020-02-20 19:33  竹石2020  阅读(203)  评论(0编辑  收藏  举报