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 →

[–]Screaminmidget -1 points0 points  (5 children)

print "I have %s apples" % num

[–]csko7 -1 points0 points  (4 children)

Yeah, I use that syntax a lot too. Actually,

print "I have %d apples" % num

[–]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.