- Learn Programming in Python with Cody Jackson
- Cody Jackson
- 89字
- 2021-06-10 19:06:05
Python 2 versus Python 3 division
While most Python 2.7 code is compatible with 3.x code, you can see that certain things don't carry over well. For example, Python 2 truncates the output of division calculations:
# Python 2
>>> 7/2
3
Python 3, as the following shows, provides the remainder when dividing. This is important to remember, as the code you're writing will break if it uses features or side effects of a particular version but is run on a different version:
# Python 3
>>> 7/2
3.5
推薦閱讀
- Learning Python Web Penetration Testing
- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- R語言經典實例(原書第2版)
- MongoDB for Java Developers
- 高級C/C++編譯技術(典藏版)
- PHP+MySQL+Dreamweaver動態網站開發實例教程
- Python Data Analysis(Second Edition)
- PLC編程與調試技術(松下系列)
- Go并發編程實戰
- Python High Performance Programming
- Learning R for Geospatial Analysis
- 智能搜索和推薦系統:原理、算法與應用
- C語言程序設計與應用(第2版)
- Python大學實用教程
- Python硬件編程實戰