如何将变量添加到字符串中?

时间:2015-08-20 14:40:54

标签: python string

我有一个空字符串 strLocation ,我想插入三个变量x,y和z,使字符串成为(x,y,z)点的位置)即可。我知道我不能简单地添加'x''y'和'z',因为这只会添加字母而不是它们持有的实际值。我该怎么办?

2 个答案:

答案 0 :(得分:3)

str_location = '({0}, {1}, {2})'.format(x, y, z)

答案 1 :(得分:2)

这样的东西
 strLocation = "("+str(x)+","+str(y)+","+str(z)+")"

相关问题