[14] What's the advantage of %s method?


#1

The exercise says that doing the %s method "is a better method than concatenating strings together" i.e. better than doing "string" + "string", but it doesn't explain why? I mean, I'm writing the variables anyway after the % () so I don't see how it'd be faster to type, if that were a reason. Is it simply because it automatically converts the variables to strings, so in case you have any number values, you don't have to use str()?

I'm not new to programming in general, so explanations are welcome to go more in depth :)


#2

That's a pretty interesting question actually. Straight out claiming that one method is better than another without further explanation isn't very good teaching. For simply printing a string with a variable or two I don't see any obvious gains.

It is also worth noting that using the %() method of printing is not recommended in newer versions of Python. Instead the new standard is using the string.format() method. (It behaves very similar, with some extra functionality and some 'under the hood'-differences).