[Tutor] Why isn't my simple if elif script not working?
Alexandre Zani
alexandre.zani at gmail.com
Wed Jul 18 19:01:30 CEST 2012
On Wed, Jul 18, 2012 at 7:44 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Alexandre Zani wrote:
>>
>> On Wed, Jul 18, 2012 at 6:09 AM, Steven D'Aprano <steve at pearwood.info>
>> wrote:
>>>
>>> Alexandre Zani wrote:
>>>
>>>> What you want to write is this:
>>>>
>>>> elif name == "John Cleese" or name == "Michael Palin":
>>>
>>>
>>> elif name in ("John Cleese", "Michael Palin"):
>>>
>>> is better.
>
>
>> Better how?
>
>
>
> It's shorter, you don't have to repeat the reference to `name` twice, it is
> more easily extensible if you add additional names, and it is likely to be a
> *tiny* bit faster -- it moves the equality test out of pure-Python code into
> a tuple method, which will be written in C.
>
Wadayano... You're right, it is faster!
Thanks.
>
>
>
> --
> Steven
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list