String formatting in Python

后端 未结 12 2115
-上瘾入骨i
-上瘾入骨i 2020-11-22 08:14

I want to do something like String.Format(\"[{0}, {1}, {2}]\", 1, 2, 3) which returns:

[1, 2, 3]

How do I do this in Python?

12条回答
  •  执念已碎
    2020-11-22 08:54

    You haven't formulated yourself very commendably, but I'll venture a guess this is what you're looking for:

    foo = "Hello"
    bar = "world"
    baz = 2
    print "%s, %s number %d" % (foo, bar, baz)
    

提交回复
热议问题