But why?


def power(base, exponent): # Add your parameters here!
result = base ** exponent
print “%d to the power of %d is %d.” % (base, exponent, result)

power(37, 4) # Add your arguments here!

Why in the print command do we write print “%d to the power of %d is %d.” % (base, exponent, result) and not just
print base + " to the power of " + exponent + " is " + result

is it just that the latter has to many quotes and +s? Both seem about equally jumbbly.



go ahead, see what happens


coolcoolcool thanks for helping me understand things.


+ is for string concatenation, although i would still go for something like .format(), which i think is more flexible and powerful.

but + for integer/decimal and string joining throws errors


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.