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")

相关推荐