RFC: For Loop Invariants

Chris Angelico rosuav at gmail.com
Fri Apr 10 21:05:48 EDT 2020


On Sat, Apr 11, 2020 at 11:04 AM Souvik Dutta <souvik.viksou at gmail.com> wrote:
>
> How about completely removing the need for an if statement by allowing for multiple conditions to be inserted in the for loop?? That would make reading and writing a lot easier. Like the count problem could be rewritten as
> for (a in chars and <the other list> ):
>     count+=1
>

A loop fundamentally has to have an iterable and an assignment target
(usually a variable). That's not a condition, it's a loop. The only
reason it looks like multiple conditions is that the "in" keyword is
doing two slightly different things here :)

ChrisA


More information about the Python-list mailing list