[Python-ideas] Nudging beginners towards a more accurate mental model for loop else clauses

Giampaolo Rodolà g.rodola at gmail.com
Fri Jun 8 17:53:04 CEST 2012

2012/6/8 Antoine Pitrou <solipsis at pitrou.net>:
> Le 08/06/2012 11:04, Nick Coghlan a écrit :
>> The only thing I'm trying to do with the tutorial update is to
>> encourage beginners to be start thinking in terms of try/except/else
>> when they first encounter for/break/else and while/break/else. That's
>> it.
> I don't see why you're trying to draw that analogy, since a loop has nothing
> in common with a try block. For the record, when I was a Python beginner, I
> had zero problem understanding the for/else construct, and it even struck me
> as very useful ("oh, they've thought about a clean and easy way to write
> search-and-break loops").
> I don't think it's useful to think of beginners as people having
> comprehension problems. Besides, if you don't understand something up front,
> there's always the possibility to come back later.
> Regards
> Antoine.

I also didn't have problems while I was learning python, and always
found for/else very expressive as a statement.
for/else is not immediately clear, meaning it is mandatory to read the
doc in order to understand what it does and what to expect, but once
you do that then you're done.

--- Giampaolo

More information about the Python-ideas mailing list