Skip to content Skip to sidebar Skip to footer

{0[jack]:d} In Python .format(), What Is The Significance Of The 'd'?

From the Python docs, I have a doubt in this part: If you have a really long format string that you don’t want to split up, it would be nice if you could reference the variab

Solution 1:

It's similar to the printf type field. As from the Python docs:

'd' Decimal Integer. Outputs the number in base 10.

This may not seem terribly useful, given that only an integer can be specified. In fact, the default format for an integer is decimal. But. The Zen of Python states:

Explicit is better than implicit.

With a complex format statement, it's helpful to have an explicit notation for a decimal integer.

Post a Comment for "{0[jack]:d} In Python .format(), What Is The Significance Of The 'd'?"