[Tutor] Bug in python
John Fouhy
john at fouhy.net
Sun Feb 19 22:31:59 CET 2006
On 20/02/06, Kermit Rose <kermit at polaris.net> wrote:
> >>> 8*a%2
> 0
> The * is being given equal priority to %.
>
> Why isn't % given higher priority than *?
Calling it a bug is a bit harsh when it's documented that way :-)
See: http://docs.python.org/ref/summary.html
*, / and % all have the same precedence. I guess the reasoning is
that / is (approximately) the inverse of * and % is "remainder after
/".
> Also, why am I getting a syntax error in the following?
When you're using the interactive interpreter, you need to end a
function definition with an extra carriage return.
(at least, that's the way it works in the console version)
eg:
>>> def foo():
... pass
... def bar():
File "<stdin>", line 3
def bar():
^
SyntaxError: invalid syntax
vs:
>>> def foo():
... pass
...
>>> def bar():
... pass
...
>>>
HTH!
--
John.
More information about the Tutor
mailing list