[Python-ideas] Anonymous blocks (again):

Juancarlo Añez apalala at gmail.com
Mon May 13 20:33:01 CEST 2013


On Mon, May 13, 2013 at 1:23 PM, Terry Jan Reedy <tjreedy at udel.edu> wrote:

> x = class (): pass
> x = with open(..):
> x = import itertools
> x = if True: y = 3
> x = <pick any statement other than expression/binding statements>
>

I can explain.

Expressions like "", [], (), {} are called "constructors" in programming
language theory, because the "construct" objects, and give them an initial
state.

In Python, functions, methods, and classes are objects too, and their
constructors are "class" and "def". But there's an asymmetry in the
language in that those two constructors don't produce an assignable value.

if, while, with, etc. are statements, not constructors. Other languages
make those return values too, but that's not the Python way of things.

Cheers,




-- 
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130513/eb51c86f/attachment.html>


More information about the Python-ideas mailing list