Hello i am currently learning how to use string formatting in python 2.7 and im slightly confused on a certain error message that gets produced in a particular scenario.
Ok so the first piece of code that i have written runs as expected which is:
print "My name is %s and my age is %d years old!" % ('Bob', 30)The second piece of slightly altered code also runs fine which is (using two (s) conversions) :
print "My name is %s and my age is %s years old!" % ('Bob', 30)However the third piece of code outputs and error (using one (d) and one (s) conversions) :
print "My name is %d and my age is %s years old!" % ('Bob', 30)
In scenario 3 I get the error message:
%d format: a number is required, not str
So my question is why is scenario 2 allowed (placing (s) conversion on an expected decimal) but the other way round in scenario 3 is not allowed. Thanks and i hope i explained my question as best as possible.