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: Complex number slicing neither works nor causes an error on immediate use
Type: behavior Stage: resolved
Components: Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: LittleMonster, eric.smith
Priority: normal Keywords:

Created on 2010-09-14 16:50 by LittleMonster, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg116409 - (view) Author: Tom (LittleMonster) Date: 2010-09-14 16:50
I hope the title of this makes sense. I've been out of things for a long time.

Going through the Python tutorial (http://docs.python.org/tutorial/introduction.html) I departed from the script to try something. It gave neither of the results I had thought it might.

    >>> (0+1j)*(0+1j).imag
    1j
    >>> (0+1j)*(0+1j).real
    0j
    >>> a=(0+1j)*(0+1j)
    >>> a.imag
    0.0
    >>> a.real
    -1.0
    >>> 

This being my first crack at this language, I may have missed something that is obvious to the more experienced.

In my naivety, I thought that slicing the result of a calculation should work - why not? It should have the same structure as that pointed to by a variable.

So I'll leave this for either somebody with the patience to put me straight or somebody to fix.

Cheers!
msg116411 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-09-14 16:58
The precedence doesn't work the way you think it does. Your example with the intermediate variable is the same as:

>>> ((0+1j)*(0+1j)).imag
0.0
>>> ((0+1j)*(0+1j)).real
-1.0

Note the extra level of parens so that .imag and .real are applied to the result of the multiplication.
msg116412 - (view) Author: Tom (LittleMonster) Date: 2010-09-14 17:02
Thanks!

I'm not surprised that it was something stupidofme like that.

Sorry to have troubled you.

:)
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54064
2010-09-14 17:02:34LittleMonstersetmessages: + msg116412
2010-09-14 16:58:06eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg116411

resolution: not a bug
stage: resolved
2010-09-14 16:50:19LittleMonstercreate