<br><br><div class="gmail_quote">On Sun, Nov 29, 2009 at 5:39 PM, Esmail <span dir="ltr"><<a href="mailto:ebonak@hotmail.com">ebonak@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Ok, this is somewhat unexpected:<br>
<br>
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)<br>
[GCC 4.3.3] on linux2<br>
Type "help", "copyright", "credits" or "license" for more information.<br>
<br>
<br>
>>> -3**2<br>
-9<br>
<br>
>>> x = -3<br>
<br>
>>> x**2<br>
9<br>
>>><br>
<br>
I would have expected the same result in both cases.<br>
<br>
Initially I would have expected -3**2 to yield 9, but I can accept<br>
that ** binds tighter than the unary -, but shouldn't the results<br>
be consistent regardless if I use a literal or a variable?<font class="Apple-style-span" color="#888888"><br></font></blockquote></div><br><div>I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation.</div>

<div><br></div><div><div>>>> (-3)**2</div><div>9</div><div>>>> 3**2</div><div>9</div><div>>>> -3**2</div><div>-9</div><div><br></div></div>