3 comments

[ 2.6 ms ] story [ 16.3 ms ] thread
What do the letters used to indicate formatting stand for?

I mean, %s for string and %f for float, but how is %d an integer?

d for decimal, o for octal, X and x for hexadecimal.
I've always heard it explained as "decimal", but in any case %i is also accepted for integers.

edit: it's not clear that this is true in python, which I missed (although experimentally it works), but it is true in at least C89, where %d and %i are equivalent for output formats, and in input formats are distinguished by %d accepting only decimal digits numbers, while %i interprets octal and hex (0-, 0x-) numbers as strtol would.