除法在 Python2 和 Python3 中的区别
总结
- Python2 中使用
from __future__ import division就可以使用python3的除法。 - Python2 中
/与操作数有关,x / y中x、y都为整型的话,为floor除法,否则为true除法也是日常的除法。 - Python3 中
/为true除法, 与操作数无关。 //在 Python2 与 Python3 中并无差别, 都代表floor除法
Python3
1 | -5/3 |
Python2
1 | -5/3 |