Using 'Or'
Marko Rauhamaa
marko at pacujo.net
Sat Jan 16 07:41:07 EST 2016
Christian Gollwitzer <auriocus at gmx.de>:
> Am 15.01.16 um 21:24 schrieb Kitten Corner:
>> print('i like pie' or 'i like donuts')
>
>> it only does the thing that's before the 'or', please help!
>
> I think you misunderstand what "or" does. It evaluates the first
> expression, and if this is false, it evaluates the second.
The fact that "or" doesn't return True but one of its arguments is a
great feature. Too bad "any" doesn't follow suit:
>>> any(x for x in ('a', 'b'))
True
>>>> import random
>>>> random.choice(('donuts','apples'))
> 'donuts'
Well, there's that. "Any" works more nicely with generators, though.
Marko
More information about the Python-list
mailing list