# Why to Use string.format() rather than % in Python

The problem with % is that the arguments are a tuple. The following code works:

w = "world"
print "Hello %s" % w


But if w was a tuple, it would raise a TypeError.
The only way to make this safe is to do this:

print "Hello %s" % (w,)


string.format() doesn’t have this problem.