[Tutor] or

Christopher Spears cspears2002 at yahoo.com
Fri Mar 30 04:29:52 CEST 2007


I was doodling at the interpreter:

>>> fruit = ["apples","pears","oranges"]
>>> for f in fruit:
...     if f != "apples":
...             print f
...             print "This is not an apple."
...
pears
This is not an apple.
oranges
This is not an apple.

What I can't remember is what is 'or' in python.  For
example, what if I want the loop to skip apples and
pears?  I tried this:

>>> for f in fruit:
...     if f != "apples" or "pears":
...             print f
...             print "This is not an apple or pear"
...
apples
This is not an apple or pear
pears
This is not an apple or pear
oranges
This is not an apple or pear
>>>

Actually maybe my problem is not asking the right
question?  Should I be looking for 'and' instead of
'or' ?


More information about the Tutor mailing list