0

I have an empty string strLocation and I would like to insert the three variables x, y and z to make the string a location of a point which is (x,y,z). I know I cannot simply add 'x' 'y' and 'z' because that will just add the letters instead of the actual values they hold. What should I do?

Yu Hao
  • 115,525
  • 42
  • 225
  • 281
  • possible duplicate of [How to print a string followed by the result of a function in Python](http://stackoverflow.com/questions/30076273/how-to-print-a-string-followed-by-the-result-of-a-function-in-python) – kylieCatt Aug 20 '15 at 14:43
  • 1
    possible duplicate of [Python string formatting: % vs. .format](http://stackoverflow.com/questions/5082452/python-string-formatting-vs-format) – mkrieger1 Aug 20 '15 at 14:46

2 Answers2

3
str_location = '({0}, {1}, {2})'.format(x, y, z)
chepner
  • 446,329
  • 63
  • 468
  • 610
2

Something like

 strLocation = "("+str(x)+","+str(y)+","+str(z)+")"

?

Arkantus
  • 122
  • 1
  • 10
  • @Kroltan It doesn't, see [this question](http://stackoverflow.com/questions/32121115/python-implicit-conversion-of-object-to-str/32121506#32121506) for someone having that problem. – SuperBiasedMan Aug 20 '15 at 15:19
  • @SuperBiasedMan Thanks for the reference. Been using Javascript for too long :) – Kroltan Aug 20 '15 at 15:19