String formatting with “{0:d}”.format gives Unknown format code 'd' for object of type 'float'
问题 If I understood the docs correctly, in python 2.6.5 string formatting "{0:d}" would do the same as "%d" with the String.format() way of formatting strings " I have {0:d} dollars on me ".format(100.113) Should print "I have 100 dollars on me " However I get the error : ValueError: Unknown format code 'd' for object of type 'float' The other format operations do work.for eg. >>> "{0:e}".format(112121.2111) '1.121212e+05' 回答1: That error is signifying that you are passing a float to the format