%s instead of %d?


On the keeping track of the produce we use

print “price: %s”

instead of

print “price: %d”

why are we formatting the price as a string while it is a number? what am i missing here?


%s corresponds to str(value) which is fine unless there’s need for something else

In any case, string interpolation with % is no longer preferred, instead:

price = 5
'price: {}'.format(price)

Or in 3.6 and later:

price = 5
f'price {price}'


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