% inside a line comes into play only after Python has determined that you use the % printf-like operator outside the line.
In the first case, you are not, so he does not complain. All you do in this case is print a line.
In the second case, you use the % operator, so it complains that you did not provide enough arguments. In this case, you format the string before printing it.
print itself knows nothing about string formatting functions; it just prints what you give it. When formatting strings, something like "Hello, %s"%("Pax") processed by the % operator to provide you with "Hello, Pax" , and then to output:
print "Hello, %s"%("Pax")
Basically, the % operator, which decides that you are doing printf-style processing, and not the fact that you have a string containing the % character. This is confirmed by the fact that:
print "%r %r %r %r %r"
also has no problem with argument counter mismatch by printing the literal %r %r %r %r %r .
source share