Logical operations
x or y | if x is false, then y, else x
Demo
>>> 0 or 1
1
>>> 0 or 0
0
- and
x and y | if x is false, then x, else y
Demo
>>> 0 and 1
0
>>> 1 and 0
0
>>> 1 and 1
1
>>>
Note:
They only evaluate their second argument, if necessary for their result.
This will return Truewhen the condition satisfies otherwise False.
Demo:
>>> "a" in "abc"
True
>>> "a" in "xyz"
False
>>>
Now about our statement:
1. 'a' in 'aeiou' return True , or, True, () True.
:
>>> 'a' in 'aeiou'
True
>>> 'a' in 'aeiou' or 'steve'
True
>>>
2. 'S' in 'Sam' return True, and, .
:
>>> 'S' in 'Sam'
True
>>> 'S' in 'Sam' and 'Steve'
'Steve'
>>>
3. , .
4. 's' in 'aeiou' return False, or, .
:
>>> 's' in 'aeiou'
False
>>> 's' in 'aeiou' or 'AEIOU'
'AEIOU'
>>>