"**" in python

Steven D'Aprano steve at pearwood.info
Mon Nov 24 05:47:37 CET 2014


On Sun, 23 Nov 2014 19:48:50 -0600, Skip Montanaro wrote:

> I want to add one more thing to the other responses. People new to
> Python often seem unaware that being an interpreted language, often the
> best way to figure something out is to simply try it at the interpreter
> prompt. The OP saw "var ** 2" in done code. The most obvious thing to me
> would have been to type
> 
> var = 42
> var ** 2
> 
> and see what happened. It's unlikely to trigger a nuclear meltdown, or
> even crash the interpreter.

Hmmm, it appears that ** is a no-op that always returns its left hand 
argument:


py> 0**2
0
py> 0**7
0
py> 0**99
0

Of course, that could be a coincidence, better try a few other things:

py> 1**57
1
py> 57**1
57
py> -1**12
-1



:-)



-- 
Steven



More information about the Python-list mailing list