How to add variables into a string?

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?

Upvotes: 1

Views: 80

Answers (2)

Arkantus
Arkantus

Reputation: 120

Something like

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

?

Upvotes: 2

chepner
chepner

Reputation: 532418

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

Upvotes: 4

Related Questions