python 除法 /与//在2.7*和3.*版本的区别
2017-03-06 11:43
316 查看
up vote down voteaccepted | In Python 3.0, 5 / 2will return 2.5and 5 // 2will return 2. The former is floating point division, and the latter is floor division, sometimes also called integer division. In Python 2.2 or later in the 2.x line, there is no difference for integers unless you perform a from __future__ import division, which causes Python 2.x to adopt the behavior of 3.0 Regardless of the future import, 5.0 // 2will return 2.0since that's the floor division result of the operation. You can find a detailed description at https://docs.python.org/whatsnew/2.2.html#pep-238-changing-the-division-operator It helps to clarify for the Python 2.x line, /is neither floor division nor true division. The current accepted answer is not clear on this. /is floor division when both args are int, but is true division when either or both of the args are float. The above tells a lot more truth, and is a lot more clearer than the 2nd paragraph in the accepted answer. from: http://stackoverflow.com/questions/183853/in-python-2-what-is-the-difference-between-and-when-used-for-division |
相关文章推荐
- python的2.5与2.7版本中ftp模块的一个小区别
- python的2.5与2.7版本中ftp模块的一个小区别
- Python3.*版本与3.*版本以下的脚本编写区别
- 举例说明python2.7.X和python3.X以上版本的区别记录学习
- Python3.0和以前版本的区别
- Centos 5.5升级Python到2.7版本
- CentOS 5升级Python版本(2.4>2.7)
- CentOS 5升级python版本(2.4>2.7)
- python 2.7 django1.6 ctype = ctype.encode(default_encoding) # omit in 3.x!
- 总结Python2(Python 2.x版本)和Python3(Python 3.x版本)之间的区别
- Python3.0和以前版本的区别
- RHEL5 5升级python版本(2.4>2.7)
- CentOS升级Python到2.7版本
- RH5.4下升级python到2.7版本
- 【python2.7】raw_input()和input()区别及用法
- Linux安装Python2.7并保留自带版本
- 使用pyinstaller制作exe, 比py2exe好很多。py2exe对python的新版本(2.7及后续版本)支持不够。
- Python字符串处理(版本2.7)-学习笔记
- Python3.0和以前版本的区别
- CentOS 5升级Python版本(2.4>2.7)