6.6. Boolean Conjunction

1 & 1 -> 1
1 & 0 -> 0
0 & 1 -> 0
0 & 0 -> 0

6.6.1. Syntax

>>> True and True
True
>>> True and False
False
>>> False and True
False
>>> False and False
False

6.6.2. Example 1

>>> firstname = 'Mark'
>>> lastname = 'Watney'
>>>
>>> firstname == 'Mark' and lastname == 'Watney'
True

Because:

>>> firstname == 'Mark'
True
>>> lastname == 'Watney'
True

Rule:

>>> True and True
True

6.6.3. Example 2

>>> firstname = 'Mark'
>>> lastname = 'Watney'
>>>
>>> firstname == 'Mark' and lastname == 'Lewis'
False

Because:

>>> firstname == 'Mark'
True
>>> lastname == 'Lewis'
False

Rule:

>>> True and False
False

6.6.4. Control Flow

>>> firstname = 'Mark'
>>> lastname = 'Watney'
>>>
>>> if firstname == 'Mark' and lastname == 'Watney':
...     print('Hello Space Pirate')
... else:
...     print('Sorry, astronauts only')
Hello Space Pirate