Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from an int to a float , why #85243

Closed
rskiredjhotmailcom mannequin opened this issue Jun 22, 2020 · 9 comments
Closed

from an int to a float , why #85243

rskiredjhotmailcom mannequin opened this issue Jun 22, 2020 · 9 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@rskiredjhotmailcom
Copy link
Mannequin

rskiredjhotmailcom mannequin commented Jun 22, 2020

BPO 41071
Nosy @tim-one, @stevendaprano, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-06-22.21:20:30.106>
created_at = <Date 2020-06-22.07:01:18.664>
labels = ['interpreter-core', 'invalid', 'type-bug', '3.7']
title = 'from an int to a float , why'
updated_at = <Date 2020-06-22.22:44:42.766>
user = 'https://bugs.python.org/rskiredjhotmailcom'

bugs.python.org fields:

activity = <Date 2020-06-22.22:44:42.766>
actor = 'rskiredj@hotmail.com'
assignee = 'none'
closed = True
closed_date = <Date 2020-06-22.21:20:30.106>
closer = 'tim.peters'
components = ['Interpreter Core']
creation = <Date 2020-06-22.07:01:18.664>
creator = 'rskiredj@hotmail.com'
dependencies = []
files = []
hgrepos = []
issue_num = 41071
keywords = []
message_count = 9.0
messages = ['372033', '372035', '372094', '372114', '372117', '372124', '372125', '372127', '372133']
nosy_count = 4.0
nosy_names = ['tim.peters', 'steven.daprano', 'serhiy.storchaka', 'rskiredj@hotmail.com']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41071'
versions = ['Python 3.7']

@rskiredjhotmailcom
Copy link
Mannequin Author

rskiredjhotmailcom mannequin commented Jun 22, 2020

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)

@rskiredjhotmailcom rskiredjhotmailcom mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jun 22, 2020
@serhiy-storchaka
Copy link
Member

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

As for reasons for changing the division operator, read PEP-238.

@stevendaprano
Copy link
Member

Mike, the bug tracker is not a help-desk for questions. There are many other forums where you can ask for help:

@rskiredjhotmailcom
Copy link
Mannequin Author

rskiredjhotmailcom mannequin commented Jun 22, 2020

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 ?

@rskiredjhotmailcom rskiredjhotmailcom mannequin reopened this Jun 22, 2020
@rskiredjhotmailcom rskiredjhotmailcom mannequin reopened this Jun 22, 2020
@tim-one
Copy link
Member

tim-one commented Jun 22, 2020

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.

@rskiredjhotmailcom
Copy link
Mannequin Author

rskiredjhotmailcom mannequin commented Jun 22, 2020

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: [bpo-41071] 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\>


@rskiredjhotmailcom
Copy link
Mannequin Author

rskiredjhotmailcom mannequin commented Jun 22, 2020

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: [bpo-41071] 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\>


@tim-one
Copy link
Member

tim-one commented Jun 22, 2020

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.

@rskiredjhotmailcom
Copy link
Mannequin Author

rskiredjhotmailcom mannequin commented Jun 22, 2020

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: [bpo-41071] 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\>


@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants