Q: Operator precedence
Pearu Peterson
pearu at cens.ioc.ee
Mon Mar 5 04:05:05 EST 2001
Section 5.12 in Python reference manual summarizes operator precedence.
I would like to have the following function:
def getprec(s):
return <the precedence number of a keyword/operator `s'>
For example,
getprec('lambda') -> 0
getprec('or') -> 1
getprec('and') -> 2
...
getprec('+') -> 11
getprec('*') -> 12
...
One solution would be tabulate the table in Sec.5.12 into a Python
dictonary and use it.
But is there a way to get this information in runtime?
Thanks,
Pearu
More information about the Python-list
mailing list