使用 % 将字典中的value嵌入到字符串中对应的key值中
dd = {"a":1,"b":2,"c":3} txt = "this is a test : a is %(a)s, b is %(b)s, c is %(c)s " print txt % dd
结果为:
this is a test : a is 1, b is 2, c is 3
时间: 2024-11-08 22:37:20
使用 % 将字典中的value嵌入到字符串中对应的key值中
dd = {"a":1,"b":2,"c":3} txt = "this is a test : a is %(a)s, b is %(b)s, c is %(c)s " print txt % dd
结果为:
this is a test : a is 1, b is 2, c is 3