Home  >  Article  >  Backend Development  >  Does python2 division have decimal point?

Does python2 division have decimal point?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-18 17:36:364230browse

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:

Does python2 division have decimal point?

# 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn