4 ms·
String Formatting with Python
- wodenokoto 8y agoWhat do the letters used to indicate formatting stand for? I mean, %s for string and %f for float, but how is %d an integer?
- DerekL 8y agod for decimal, o for octal, X and x for hexadecimal.
- naniwaduni 8y agoI'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.