This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: from an int to a float , why
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: rskiredj@hotmail.com, serhiy.storchaka, steven.daprano, tim.peters
Priority: normal Keywords:

Created on 2020-06-22 07:01 by rskiredj@hotmail.com, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (9)
msg372033 - (view) Author: mike stern (rskiredj@hotmail.com) Date: 2020-06-22 07:01
please I would like to know why python changes an integer result in a division to a float even in the result is even

like print(2 / 2) gives 2.0 instead of 2

or 

a = 2 / 2
print(a)
msg372035 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-06-22 07:14
I cannot reproduce. 2 / 2 gives 1.0 to me.

As for reasons for changing the division operator, read PEP 238.
msg372094 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-06-22 15:29
Mike, the bug tracker is not a help-desk for questions. There are many other forums where you can ask for help:

- the python-list and tutor mailing lists 
  https://www.python.org/community/lists/

- Stackoverflow

- The Python IRC channel https://www.python.org/community/irc/

- Reddit's r/learnpython

- https://python-forum.io/
msg372114 - (view) Author: mike stern (rskiredj@hotmail.com) Date: 2020-06-22 21:07
Not satisfied with that reply

you can't just decide to close the ticket without even giving a reasonable answer, or even try that on 2.7 or 3.7 to see if it is true what I said.
Besides, that is not a convincing answer, that is actually no answer at all!!!

I made my research and this is what is it 
https://stackoverflow.com/questions/183853/what-is-the-difference-between-and-when-used-for-division

in python 2.7 
print((20 / 3)) ----> 6
but
print((20.0 / 3)) or print((20 / 3.0)) or print((20.0 / 3.0)) ----> 6.66666666667
however 
print((20 / 2)) ----> 10 # integer number


in python 3.7
print((20 / 3)) ----> 6.66666666667
not only that but even
print((20 / 2)) ----> 10.0  # float number
unless you use //
print((20 // 2)) ----> 10

can someone really explain this ?
msg372117 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2020-06-22 21:20
Read the PEP Serhiy already linked to:

https://www.python.org/dev/peps/pep-0238/

This was a deliberate change to how "integer / integer" works, introduced with Python 3.
msg372124 - (view) Author: mike stern (rskiredj@hotmail.com) Date: 2020-06-22 21:52
I appreciate your answer
I just didn't like how she answered earlier saying

I cannot reproduce. 2 / 2 gives 1.0 to me.

which is not true

thanks anyway, now i am gonna have to do some reading

________________________________
From: report=bugs.python.org@roundup.psfhosted.org <report=bugs.python.org@roundup.psfhosted.org> on behalf of Tim Peters <report@bugs.python.org>
Sent: Monday, June 22, 2020 5:20 PM
To: rskiredj@hotmail.com <rskiredj@hotmail.com>
Subject: [issue41071] from an int to a float , why

Tim Peters <tim@python.org> added the comment:

Read the PEP Serhiy already linked to:

https://www.python.org/dev/peps/pep-0238/

This was a deliberate change to how "integer / integer" works, introduced with Python 3.

----------
nosy: +tim.peters
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue41071>
_______________________________________
msg372125 - (view) Author: mike stern (rskiredj@hotmail.com) Date: 2020-06-22 21:54
sorry but that article was about version 2.2 in 2000

Created:        11-Mar-2001
Python-Version: 2.2

where is the one for 3.7

________________________________
From: report=bugs.python.org@roundup.psfhosted.org <report=bugs.python.org@roundup.psfhosted.org> on behalf of Tim Peters <report@bugs.python.org>
Sent: Monday, June 22, 2020 5:20 PM
To: rskiredj@hotmail.com <rskiredj@hotmail.com>
Subject: [issue41071] from an int to a float , why

Tim Peters <tim@python.org> added the comment:

Read the PEP Serhiy already linked to:

https://www.python.org/dev/peps/pep-0238/

This was a deliberate change to how "integer / integer" works, introduced with Python 3.

----------
nosy: +tim.peters
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue41071>
_______________________________________
msg372127 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2020-06-22 21:59
Mike, read that exchange again. You originally wrote

"print(2 / 2) gives 2.0 instead of 2"

but you didn't _mean_ that. You meant to say it "gives 1.0 instead of 1", or you meant something other than "2 / 2").  In Python 3,

>>> print(2 / 2)
1.0

Which is what Serhiy said it does.

For the rest, read the PEP again after you calm down. In particular,

"Classic division will remain the default in the Python 2.x series; true division will be standard in Python 3.0."

Also all true.
msg372133 - (view) Author: mike stern (rskiredj@hotmail.com) Date: 2020-06-22 22:44
i am calm

but sometimes I am wondering if the philosophy behind python is really like they claimed to make it very simple. Well I see a lot of confusions sometimes , and this is one

________________________________
From: report=bugs.python.org@roundup.psfhosted.org <report=bugs.python.org@roundup.psfhosted.org> on behalf of Tim Peters <report@bugs.python.org>
Sent: Monday, June 22, 2020 5:59 PM
To: rskiredj@hotmail.com <rskiredj@hotmail.com>
Subject: [issue41071] from an int to a float , why

Tim Peters <tim@python.org> added the comment:

Mike, read that exchange again. You originally wrote

"print(2 / 2) gives 2.0 instead of 2"

but you didn't _mean_ that. You meant to say it "gives 1.0 instead of 1", or you meant something other than "2 / 2").  In Python 3,

>>> print(2 / 2)
1.0

Which is what Serhiy said it does.

For the rest, read the PEP again after you calm down. In particular,

"Classic division will remain the default in the Python 2.x series; true division will be standard in Python 3.0."

Also all true.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue41071>
_______________________________________
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85243
2020-06-22 22:44:42rskiredj@hotmail.comsetmessages: + msg372133
2020-06-22 21:59:57tim.peterssetmessages: + msg372127
2020-06-22 21:54:25rskiredj@hotmail.comsetmessages: + msg372125
2020-06-22 21:52:26rskiredj@hotmail.comsetmessages: + msg372124
2020-06-22 21:20:30tim.peterssetstatus: open -> closed


messages: + msg372117
nosy: + tim.peters
2020-06-22 21:07:24rskiredj@hotmail.comsetstatus: closed -> open

messages: + msg372114
2020-06-22 15:29:35steven.dapranosetnosy: + steven.daprano
messages: + msg372094
2020-06-22 07:14:19serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg372035

resolution: not a bug
stage: resolved
2020-06-22 07:01:18rskiredj@hotmail.comcreate