%s instead of %d?


#1

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?


#2

%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}'

#3

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