semantics of ** (unexpected/inconsistent?)
"Martin v. Löwis"
martin at v.loewis.de
Sun Nov 29 20:03:46 EST 2009
>> I think you answered your own question. 3**2 comes first in the order
>> of operations, followed by the negation.
>
> No, that's not the problem, I'm ok with the operator precedence of - vs **
>
> My problem is why I don't get the same result if I use the literal -3 or
> a variable that contains -3 (x in my example).
There is no literal -3 in Python, only a literal (+)3, see
http://docs.python.org/reference/lexical_analysis.html#integer-and-long-integer-literals
So -3**2 means -(3**2) == -9.
Regards,
Martin
More information about the Python-list
mailing list