>>> Using "in ['25', '26']" also checks a compiled tuple constant:
>>>
>...
>>> 3.x adds frozenset support:
>>>
>>>      >>> compile("x in {'25', '26'}", '', 'eval').co_consts
>>>      ('25', '26', frozenset({'25', '26'}))
>>
>>
>> I confess I don't know what that means!
>
>Sorry, I was showing that the compiler (at least for CPython) special
>cases "in" and "not in" comparisons when the right-hand operand is a
>list literal of constants. Instead of going to the trouble of building
>a list every time the code runs, it uses a tuple that's stored in the
>code object's co_consts attribute.
>Ah, OK that makes sense now, thanks. Not sure that beginners will 
make much of it but the gist is that Python will optimise the test. :-)

Alan g.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to