0

Going through the python doc and doing the following operation:

ravi@user-ThinkCentre-M90:~$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 17/3
5
>>>

Why the output is not a float num?

Teoretic
  • 2,483
  • 1
  • 19
  • 28
Ravi
  • 239
  • 2
  • 14
  • 5
    `from __future__ import division` for the new behaviour, python 2 uses floor division by default – Chris_Rands Sep 28 '18 at 09:48
  • the result type will be **int** in **Python 2.7** which is you are using and the result type will be float in all **python 3.x** versions. You can read all the details in the [PEP 238](https://www.python.org/dev/peps/pep-0238/). You will get the new behavior by using the future statement suggested by @Chris_Rands – Iyvin Jose Sep 28 '18 at 09:56

2 Answers2

2

try dividing it this way:

17/3.0
Ogs
  • 167
  • 3
  • 15
2

you should use 17/3.0

It is a different place of python2 and python3.

tianhua liao
  • 655
  • 5
  • 9