for statement on empty iterable

Paul Rubin http
Wed Aug 22 01:33:45 EDT 2007


james_027 <cai.haibin at gmail.com> writes:
> for i in []:
>  #do something
> is this safe? or should I put a if statement to test it first?

That doesn't crash or anything like that, but it also doesn't
set the index variable, which can cause confusion in some situations.



More information about the Python-list mailing list