it seems like a few weeks ago... but actually it was more like 30 years ago that i was programming in C, and
inhahe
inhahe at gmail.com
Mon Feb 27 04:05:56 EST 2023
On Mon, Feb 27, 2023 at 3:56 AM inhahe <inhahe at gmail.com> wrote:
>
>
> On Mon, Feb 27, 2023 at 3:52 AM Roel Schroeven <roel at roelschroeven.net>
> wrote:
>
>> Op 26/02/2023 om 6:53 schreef Hen Hanna:
>> > > There are some similarities between Python and Lisp-family
>> > > languages, but really Python is its own thing.
>> >
>> >
>> > Scope (and extent ?) of variables is one reminder that Python is
>> not Lisp
>> >
>> > for i in range(5): print( i )
>> > .........
>> > print( i )
>> >
>> > ideally, after the FOR loop is done, the (local) var i should also
>> disappear.
>> > (this almost caused a bug for me)
>> I wouldn't say "i *should* also disappear". There is no big book of
>> programming language design with rules like that that all languages have
>> to follow. Different languages have different behavior. In some
>> languages, for/if/while statements introduce a new scope, in other
>> languages they don't. In Python, they don't. I won't say one is better
>> than the other; they're just different.
>>
>> --
>>
>>
> I'm not sure, but I think I remember this was actually a bug in the
> interpreter, and presumably they didn't fix it because they didn't want to
> break backward compatibility?
>
>
Maybe I'm thinking of a variable scope leak after list comprehensions.
More information about the Python-list
mailing list