But why?


#1

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.

Thanks!!!


#2

go ahead, see what happens


#3

coolcoolcool thanks for helping me understand things.


#4

+ 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


#5

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