Behavior of the for-else construct

computermaster360 computermaster360 at gmail.com
Thu Mar 3 14:38:33 EST 2022


On Thu, 3 Mar 2022 at 18:25, Schachner, Joseph
<Joseph.Schachner at teledyne.com> wrote:
>  I don't know what that would be. "finally" is available 😊  Write up a feature request.

Not sure if you mean `finally` seriously but I think that would about
as confusing as the current `else`, if not even more 😅

Meanwhile, I found another solution which is somewhat neater than
using a boolean flag:

    item = sentinel = object()
    for item in iterable:
        do_stuff(item)

    if item is sentinel:
        print('No items in iterable!')


More information about the Python-list mailing list