List of all syntactic sugar?

Bas wegwerp at gmail.com
Fri Apr 14 05:54:11 EDT 2006


Hi group,

just out of curiosity, is there a list of all the syntactic sugar that
is used in python? If there isn't such a list, could it be put on a
wiki somewhere? The bit of sugar that I do know have helped me a lot in
understanding the inner workings of python.

To give a few examples (might not be totally correct):

x[i] -> x.__getitem__(i)
x[a:b] -> x.__getitem__(slice(a,b,None))
x+y -> x._add__(y)
x.method(a) -> call (x.__dict__[method], self, a) ??
for i in x: f(i) -> it = iter(x); while True: i = it.next(); f(i) ....
except stop: pass

TIA,
Bas




More information about the Python-list mailing list