Alexandre Zani wrote:
On Wed, Jul 18, 2012 at 6:09 AM, Steven D'Aprano <st...@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.



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

Reply via email to