python float to in int conversion

前端 未结 4 1906
孤城傲影
孤城傲影 2021-01-12 08:26

I have an issue that really drives me mad. Normally doing int(20.0) would result in 20. So far so good. But:

levels = [int(gex_dict         


        
4条回答
  •  失恋的感觉
    2021-01-12 08:57

    It looks like the problem is that gex_dict[i] actually returns a string representation of a float '20.0'. Although int() has the capability to cast from a float to an int, and a string representation of an integer to an int. It does not have the capability to cast from a string representation of a float to an int.

    The documentation for int can be found here: http://docs.python.org/library/functions.html#int

提交回复
热议问题