Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
String Formatting with Python (kite.com)
11 points by brendanmcd on Feb 20, 2019 | hide | past | favorite | 3 comments


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?


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.


d for decimal, o for octal, X and x for hexadecimal.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: