1

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
  • 119,891
  • 44
  • 235
  • 294
Stack_Protégé
  • 302
  • 1
  • 15
  • 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

4
str_location = '({0}, {1}, {2})'.format(x, y, z)
chepner
  • 497,756
  • 71
  • 530
  • 681
2

Something like

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

?

Arkantus
  • 120
  • 1
  • 10