python for loop

Chris Rebert clp2 at rebertia.com
Tue Mar 31 22:29:56 EDT 2009


On Tue, Mar 31, 2009 at 7:13 PM, Lada Kugis <lada.kugis at gmail.com> wrote:
> On Tue, 31 Mar 2009 21:13:05 -0400 (CLT), "andrew cooke"
> <andrew at acooke.org> wrote:
>
>>Lada Kugis wrote:
>>> I'm coming from fortran and
>>   *********** c ***********
>>> background so I'm certainly biased by
>>> them. But if you could explain one thing to me:
>>
>>but this is exactly the same behaviour as the standard way of doing things
>>in c!
>>
>>int a[5];
>>for (i = 0; i < 5; ++i) {
>>  a[i] = 0;
>>}
>>
>>were you being honest about the c background?!
>>
>
> :-)
> Yes, I usually avoid lyes. They are hard to remember.
>
> In C you can do it either way

Sort of, but it's *really* not idiomatic. You'd have to declare the
arrays to be one longer than they actually are so that array[N] is a
valid index. And then you'd end up not using the true first element of
the array. Not to mention most library functions use 0-numbering, so
you'd have to work around that as well.

So, it can be done, but you're going against the grain of the language.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-list mailing list