关于 python2.7 中的 int () 函数
各位观众,大家好,相信大家都知道在python中类型转化是非常方便的,比如int(param)可以把param转成int,float(param)可以转成float,但是我最近遇上了一个问题,在执行int()时报错了,去看了一下原因,原来我的存储格式之前是float(eg:2.0),然后缓存redis时变成了string(eg:”2.0”),然后这个格式不能直接转成int,需要先转float,再转成int,即int(float(param))才可以。
不知道为什么设计成这样,纯数字str转int可不可以自动过滤小数点之后呢?大家支持的顶起来
推荐文章: