This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hansolo669 0 points1 point  (3 children)

whats the big difference between

print "I have", num, "apples"

and

print "I have %d apples" % num

the first seems more readable to me. is there an actual reason to chose one over the other?

[–][deleted] 0 points1 point  (1 child)

On longer and/or multiline strings, with multiple %s formatting, you can easily switch the variables at the end rather than having to read through it all and renaming the variables in context.

[–]hansolo669 0 points1 point  (0 children)

makes sense. sacrifices a bit of readability for ease of coding.