Difference between using commas, concatenation, and string formatters in Python
23:43 03 Feb 2014

I am learning python(2.7) on my own. I have learned that we can use the following ways to put strings and variables together in printing:

x = "Hello"
y = "World"

By using commas:

print "I am printing" , x, y  # I know that using comma gives automatic space

By using concatenation :

print "I am printing" + " " + x + " " + y 

By using string formatters

print "I am printing %s %s" % (x, y) 

In this case all three print the same:

I am printing Hello World

What is the difference between the three and are there any particular instances where one is preferred over the other?

python string