python3中Error Message: ‘float’ object cannot be interpreted as an integer
来源:互联网 发布:kx tda100 软件 编辑:程序博客网 时间:2024/05/28 11:49
背景:
BMPixel
194***4370@qq.com
列表反转函数:
#!/user/bin/python# -*- coding: UTF-8 -*-def reverse(li): for i in range(0, len(li)/2): temp = li[i] li[i] = li[-i-1] li[-i-1] = templ = [1, 2, 3, 4, 5]reverse(l)print(l)
问题解决
为什么range内的数据是float呢 ?
怀疑/
在py2跟py3之间有差别,搜了一下,的确是有差别。请看下面的用法:
pyhon2
C:\Users\chenjun>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (
AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> 0/200 + 1
1
>>> 1/200 + 1
1
python3
C:\Users\chenjun>python3
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]
on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> 0/200 + 1
1.0
>>> 1/200 + 1
1.005
在python2,/
只留下了整数部分,去掉了小数,是int型。而在python3里,/
的结果是真正意义上的除法,结果是float型。所以便出现了Error Message: ‘float’ object cannot be interpreted as an integer。
解决办法:将float类型强转化为int类型就可以了
- python3中Error Message: ‘float’ object cannot be interpreted as an integer
- python-Error Message: 'float' object cannot be interpreted as an integer
- TypeError: 'float' object cannot be interpreted as an integer
- TypeError: 'numpy.float64' object cannot be interpreted as an integer
- TypeError numpy.float64 object cannot be interpreted as an index
- TypeError: 'numpy.float64' object cannot be interpreted as an index
- TypeError: 'numpy.float64' object cannot be interpreted as an index
- TypeError numpy.float64 object cannot be interpreted as an index
- TypeError: 'numpy.float64' object cannot be interpreted as an index
- TypeError numpy.float64 object cannot be interpreted as an index解决
- Windows下TypeError numpy.float64 object cannot be interpreted as an index的解决
- “An error message cannot be displayed because an optional resource assembly containing it cannot be found“ 怎么解决
- python write出现 Non-character array cannot be interpreted as character buffer.
- 调试CRF出现的错误:cannot be interpreted as a Tensor.
- Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
- PHP中遍历stdclass object 报错Fatal error: Cannot use objectof type stdClass as array
- session中Integer cannot be cast to java.lang.String
- PLS-00363: expression 'v_s' cannot be used as an assignment target
- 构建消息推送系统之HTTP长连接实践
- fatal error in launcher:unable to create process using 解决办法
- Django联表查询
- Linux下配置XAMPP开启GZIP压缩功能
- 第七届蓝桥杯-搭积木
- python3中Error Message: ‘float’ object cannot be interpreted as an integer
- 初涉linux
- 关于iview表单验证select标签在使用v-for的时候验证一直不通过的问题
- JVM之堆
- 使用easyBCD安装ubuntu双系统
- 习题6.8
- 6.7
- 配置mysql
- No modules name apps解决