classification
Title: identity operator
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, eric.smith, roccosan, terry.reedy
Priority: normal Keywords:

Created on 2019-04-04 12:28 by roccosan, last changed 2019-04-05 00:58 by eric.smith. This issue is now closed.

Messages (7)
msg339441 - (view) Author: Rocco Santoro (roccosan) Date: 2019-04-04 12:28
Hi all

Why the identity operator and '=='  are both applied to the type (see above)? Is it not convenient to distinguish them? I mean the identity operator  applied to the type and '==' applied to the outcome.
Thanks for the attention
Best regards
Rocco Santoro

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import math
>>> x = math.log(10000000)
>>> y = math.log(10)
>>> print(x/y) == x/y
7.0
False
>>> print(math.log(10000000)/math.log(10)) == math.log(10000000)/math.log(10)
7.0
False
>>> x = math.sin(32)
>>> y = math.cos(41)
>>> print(y/x) == y/x
-1.7905177807148493
False
>>> x = math.pi
>>> y = math.tau
>>> x/y == print(x/y)
0.5
False
>>> x = 153
>>> y = 245
>>> print(x/y) == x/y
0.6244897959183674
False
>>> print(x+y) == x + y
398
False
>>> print(x*y) == x*y
37485
False
>>> s1 = 'Hello, '
>>> s2 = 'how are you?'
>>> print(s1 + s2) == s1 + s2
Hello, how are you?
False
>>> print(s1 + s2) is s1 + s2
Hello, how are you?
False
>>> type(print(s1 + s2))
Hello, how are you?
<class 'NoneType'>
>>> type(s1 + s2)
<class 'str'>
>>> type(print(y/x))
1.6013071895424837
<class 'NoneType'>
>>> type(x/y)
<class 'float'>
msg339442 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2019-04-04 12:35
I'm not sure what you're asking here. You're comparing the result of the print function to a value. Print returns None, so it doesn't compare equal to any of the values you're comparing it to.

To see what's happening, try:

>>> print(None) == None
None
True

But really, your problem is probably a misunderstanding of the return value of the print function.
msg339443 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-04-04 12:37
You seem to be confused by the fact that print function returns None and therefore all the comparisons you're making return False. There is not type vs "outcome" difference in your code sample.
msg339456 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-04-04 17:21
Rocco, please ask questions about Python on python-list or places like stackoverflow.com.  1. If python behavior puzzles you, the chance that it is a python bug is well less than 1 in 1000.  2. The answer you get will be much more visible to others who have similar questions.

Also, when you use the IDLE IDE to execute your python code, IDLE submits your code to a running python.exe process and displays the answer received from that process.  The answer is nearly always the same as when you submit the same code to python yourself.  'IDLE' is for questions about IDLE behavior rather than Python behavior.
msg339461 - (view) Author: Rocco Santoro (roccosan) Date: 2019-04-04 20:23
Thanks you very much for the explanations. I am sorry for bothering you, actually my question concerned the use of identity operator. I suggest that '=='  means equal not identity. Therefore, it concerns the instance not the ontology and makes a comparison between the values not the types. In my modest opinion this is a bug. Anyway, you have explain very well the class None and the role of print as function in Python. My little remark is that a communication act should not change the type of object that shows. Instead it transforms the object in Noneclass. This is a peculiar of Python. Warm regards. Rocco
msg339463 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-04-04 20:42
Rocco, == is an equality operator, "is" is used for identity testing. If you have an example of documentation that states that == is an identity operator, do report it and we'd be glad to fix it.

The print function does not change the object, it's the print function itself that return None.
msg339466 - (view) Author: Rocco Santoro (roccosan) Date: 2019-04-04 22:21
You are right. The documentation, that I know, is clear. Anyway in this case "is" and "==" provides the same outcome and this is my remark, that I called bug, wrongly. The reason is the nature of print(), as function, that always remains always NoneType with only the value None.  Nevertheless, print, as method, could be referred to the object. 
This is my goofy remark about the contraddiction between the message of the communication by print method and the nature of the communication by print function. 
Therefore, the monitor tells you that two things are not equals because they are two different ways to say the same message. Thanks a lot for the patience
History
Date User Action Args
2019-04-05 00:58:33eric.smithsetnosy: + eric.smith
2019-04-04 22:21:41roccosansetmessages: + msg339466
2019-04-04 20:42:08SilentGhostsetmessages: + msg339463
2019-04-04 20:23:15roccosansetmessages: + msg339461
2019-04-04 17:21:29terry.reedysetmessages: + msg339456
components: - IDLE
2019-04-04 12:37:01SilentGhostsetstatus: open -> closed
nosy: + SilentGhost, - eric.smith
messages: + msg339443

assignee: terry.reedy ->
resolution: not a bug
stage: resolved
2019-04-04 12:35:16eric.smithsetnosy: + eric.smith
messages: + msg339442
2019-04-04 12:28:43roccosancreate