[Tutor] Very basic question about lists

Eduardo Vieira eduardo.susan at gmail.com
Mon Dec 22 19:33:10 CET 2008


Hello, I'm trying to teach my self programming with python and there
are some basic things that stumps me:
Given this code:
###
list1 = ['arr', 'bre', 'grau', 'lower', 'tudo']
for item in list1:
    if 'arr' in item:
        print list1
###
The output is (as expected):
['arr', 'bre', 'grau', 'lower', 'tudo']

If I change my condition to:
if 'arr' or 'bell' in item:
or to this:
if 'arr' or 'grau' in item:

I get this result:
['arr', 'bre', 'grau', 'lower', 'tudo']
['arr', 'bre', 'grau', 'lower', 'tudo']
['arr', 'bre', 'grau', 'lower', 'tudo']
['arr', 'bre', 'grau', 'lower', 'tudo']
['arr', 'bre', 'grau', 'lower', 'tudo']

Why this? I guess I'm not grasping the use of AND and OR

Thanks,

Eduardo


More information about the Tutor mailing list