Home >Backend Development >Python Tutorial >Does python2 division have decimal point?
Does python2 division have a decimal point? When using division in python2, only the integer part is taken and the decimal part is not retained, so there is no decimal point. But you can also let python2 retain the decimal part by importing a division package.
1. The biggest difference between python2 and python3 division:
# python2 takes the integer part and does not retain the decimal part
>>> 53/3 17
# python3 gets real results, decimals are retained
Related recommendations: "python video tutorial"
>>> 53/3 17.666666666666668
2. If python2 wants to How to retain the decimal part?
(1) Just add an import package
>>> from __future__ import division >>> 53/3 17.666666666666668
(2) Another way. Add the divisor or dividend to at least two other One converted to float type:
>>> float(53)/3 17.666666666666668
The above is the detailed content of Does python2 division have decimal point?. For more information, please follow other related articles on the PHP Chinese website!